emersion / kanshi

Dynamic display configuration (mirror)
https://wayland.emersion.fr/kanshi/
MIT License
655 stars 46 forks source link

Zombie processes #82

Closed cyb3rd4d closed 4 years ago

cyb3rd4d commented 4 years ago

Hello

My kanshi configuration seems to be a little bit problematic. I run kanshi on sway, and I need to move my workspaces depending on the profile. Here is my configuration file:

profile soad {
    output eDP-1 enable mode 1920x1080 position 0,0

    exec swaymsg workspace "1: www", move workspace to eDP-1
    exec swaymsg workspace "2: email", move workspace to eDP-1
    exec swaymsg workspace "3: chat", move workspace to eDP-1
    exec swaymsg workspace "4: visio", move workspace to eDP-1
    exec swaymsg workspace "5: term", move workspace to eDP-1
    exec swaymsg workspace "6: code", move workspace to eDP-1
    exec swaymsg workspace "7: gaming", move workspace to eDP-1
    exec swaymsg workspace 8, move workspace to eDP-1
    exec swaymsg workspace 9, move workspace to eDP-1
    exec swaymsg workspace 10, move workspace to eDP-1
}

profile soad-home {
    output eDP-1 disable
    output DP-2 mode 1920x1080 position 0,0
    output HDMI-A-1 mode 1920x1080 position 1920,0

    exec swaymsg workspace "1: www", move workspace to DP-2
    exec swaymsg workspace "2: email", move workspace to DP-2
    exec swaymsg workspace "3: chat", move workspace to DP-2
    exec swaymsg workspace "4: visio", move workspace to DP-2
    exec swaymsg workspace "5: term", move workspace to HDMI-A-1
    exec swaymsg workspace "6: code", move workspace to HDMI-A-1
    exec swaymsg workspace "7: gaming", move workspace to HDMI-A-1
    exec swaymsg workspace 8, move workspace to HDMI-A-1
    exec swaymsg workspace 9, move workspace to HDMI-A-1
    exec swaymsg workspace 10, move workspace to HDMI-A-1
}

profile yoda {
    output DP-2 mode 1920x1080 position 0,0
    output DP-1 mode 1920x1080 position 1920,0
}

Kanshi works fine, executes the swaymsg commands, but sometimes the kanshi process dies. So I started to look for some clues and I found that it generated zombie processes:

martial    20882  0.0  0.0   2604  1792 pts/1    S+   15:28   0:00 kanshi
martial    20884  0.0  0.0      0     0 ?        Zs   15:28   0:00 [kanshi] <defunct>
martial    20885  0.0  0.0      0     0 ?        Zs   15:28   0:00 [kanshi] <defunct>
martial    20886  0.0  0.0      0     0 ?        Zs   15:28   0:00 [kanshi] <defunct>
martial    20887  0.0  0.0      0     0 ?        Zs   15:28   0:00 [kanshi] <defunct>
martial    20888  0.0  0.0      0     0 ?        Zs   15:28   0:00 [kanshi] <defunct>
martial    20889  0.0  0.0      0     0 ?        Zs   15:28   0:00 [kanshi] <defunct>
martial    20890  0.0  0.0      0     0 ?        Zs   15:28   0:00 [kanshi] <defunct>
martial    20891  0.0  0.0      0     0 ?        Zs   15:28   0:00 [kanshi] <defunct>
martial    20892  0.0  0.0      0     0 ?        Zs   15:28   0:00 [kanshi] <defunct>
martial    20893  0.0  0.0      0     0 ?        Zs   15:28   0:00 [kanshi] <defunct>

I run Kanshi 1.1.0 on Arch (community repository, not AUR). I can post the output of a strace if you need.

emersion commented 4 years ago

Hmm, it seems like our double-fork logic is incorrect. We should waitpid in the parent, not in the child. The child should execute the grandchild and then exit.

https://github.com/emersion/kanshi/blob/e55b5847a07bc3ea2dc19f3cdce8d88c8aa2f9ca/main.c#L97

layus commented 4 years ago

Funny, I just noticed the same thing. I really wanted to give some information on the subprocess, which you can only do if you wait for it. I guess it was useful for debugging.

We could either fork a third time, or just stop trying to give this exit info. Debugging can be done in the invoked command anyway.

emersion commented 4 years ago

stop trying to give this exit info

Yeah, I'd prefer to do that.

layus commented 4 years ago

Wish... fulfilled :-) #85