8000 Polybar kills all children of processes it spawns? · Issue #770 · polybar/polybar · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

Polybar kills all children of processes it spawns? #770

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
apetresc opened this issue Sep 23, 2017 · 7 comments
Closed

Polybar kills all children of processes it spawns? #770

apetresc opened this issue Sep 23, 2017 · 7 comments
Labels

Comments

@apetresc
Copy link

So, I have a shell script that launches mpv in the background to connect to my remote MPD server:

$ cat $(which stream-mpd)
#!/bin/bash
pkill -f "mpv http://mysever"
mpv http://myserver &

If I launch this from the command line, everything works as it should, mpv runs in the background even if I close the terminal, etc. However, if I try to hook it up to my mpd module in polybar (so that I can actually listen to the stream that I am remote-controlling with the module) like so:

format- %{A}  <icon-prev> <icon-seekb> <icon-stop> <toggle> <icon-seekf> <icon-next>  <icon-repeat> <icon-random>

then something strange happens: the mpv process is killed as soon as stream-mpd exits. I can confirm this by adding a sleep 10 as the last line of my script: polybar will freeze up for 10 seconds since the script is running, but then once the 10 seconds are up, mpv is killed too! I can't explain why that happens - is polybar going out of its way to clean up the children of all the processes it spawns? Is there a way to accomplish what I'm after (which is to start a background task as an input trigger)?

@patrick96
Copy link
Member

I don't exactly know how polybar handles its child processes, but it makes sense that it cleans up after itself, otherwise you end up with a bunch of processes spawned by polybar which run in the background (not necessarily doing anything or outputting text to the bar without the bar listening for it) or you may even get zombie processes, if they're not handled correctly.

But what you want to achieve is possible inside the script, with one of the following ways:

nohup:

nohup mpv http://myserver &>/dev/null &

disown:

mpv http://myserver &
disown

setsid:

setsid mpv http://myserver &>/dev/null < /dev/null &

The setsid version is probably the one that will always work, it directly attaches the process to the init process. It is possible that if you use the nohup or disown variants that the mpv process is still terminated when the script is terminated but that may depend on the shell and on how the script is terminated.

@apetresc
Copy link
Author

Thank you for the super-thorough explanation. The setsid solution is indeed best. Cheers!

patrick96 added a commit to patrick96/polybar that referenced this issue Nov 25, 2020
Shell commands triggered from action tags used to block polybar until
they finished.

Since we are not actually interested in the output of the commands, it
makes sense to run them completely detached from polybar and have
polybar not block when executing these commands.

Now the spawned child processes no longer get killed when polybar
exits. This is fine because polybar is not responsible for these
processes since they were explicitly started by the user through click
commands.

Ref: polybar#770
@patrick96
Copy link
Member
patrick96 commented Nov 25, 2020

Just FYI, I have just pushed #2248 which will make polybar no longer kill children spawned through click (and scroll) commands. Programs launched through polybar now act more or less the same as if they were started from some application launcher.

EDIT: This should make it into the 3.5.0 release

patrick96 added a commit to patrick96/polybar that referenced this issue Nov 25, 2020
Shell commands triggered from action tags used to block polybar until
they finished.

Since we are not actually interested in the output of the commands, it
makes sense to run them completely detached from polybar and have
polybar not block when executing these commands.

Now the spawned child processes no longer get killed when polybar
exits. This is fine because polybar is not responsible for these
processes since they were explicitly started by the user through click
commands.

Ref: polybar#770
Ref: polybar#1680
patrick96 added a commit to patrick96/polybar that referenced this issue Nov 29, 2020
Shell commands triggered from action tags used to block polybar until
they finished.

Since we are not actually interested in the output of the commands, it
makes sense to run them completely detached from polybar and have
polybar not block when executing these commands.

Now the spawned child processes no longer get killed when polybar
exits. This is fine because polybar is not responsible for these
processes since they were explicitly started by the user through click
commands.

Ref: polybar#770
Ref: polybar#1680
patrick96 added a commit that referenced this issue Nov 29, 2020
Shell commands triggered from action tags used to block polybar until
they finished.

Since we are not actually interested in the output of the commands, it
makes sense to run them completely detached from polybar and have
polybar not block when executing these commands.

Now the spawned child processes no longer get killed when polybar
exits. This is fine because polybar is not responsible for these
processes since they were explicitly started by the user through click
commands.

Ref: #770
Ref: #1680
@pawel-szopinski
Copy link

@patrick96 I am on 3.5.0, and now, even the simplest command executed with mouse click (e.g. notify-send "hello" "world") leaves a zombie process. See the screenshot below. These processes do not seem to disappear after a while. They (obviously) are removed after polybar is restarted.

image

patrick96 added a commit to patrick96/polybar that referenced this issue Dec 12, 2020
Since the forked processes are still our children, we need to wait on
them, otherwise they become zombie processes.

We now fork twice, let the first fork immediately return and wait on it.
This reparents the second fork, which runs the actual code, to the init
process which then collects it.

Ref polybar#770
patrick96 added a commit to patrick96/polybar that referenced this issue Dec 12, 2020
Since the forked processes are still our children, we need to wait on
them, otherwise they become zombie processes.

We now fork twice, let the first fork immediately return and wait on it.
This reparents the second fork, which runs the actual code, to the init
process which then collects it.

Ref polybar#770
patrick96 added a commit that referenced this issue Dec 12, 2020
Since the forked processes are still our children, we need to wait on
them, otherwise they become zombie processes.

We now fork twice, let the first fork immediately return and wait on it.
This reparents the second fork, which runs the actual code, to the init
process which then collects it.

Ref #770
@patrick96
Copy link
Member

@pawel-szopinski Hmm, I though I tested this exact thing, but I guess I did not. I fixed this in #2285, this will be in the 3.5.1 release.

patrick96 added a commit that referenced this issue Dec 12, 2020
Changelog

**Features**

* config: Multiple inheritance (#2271), see #2269

**Fixes**

* (#2285), see #770, #2289
* Timer module: Polybar crash when interval is set to 0 (#2274), see #2273
* `custom/menu`: Wrong level numbers in error messages (#2264)
* `internal/xworkspaces`: Ignored certain workspace updates (#2275), see #2272
* Logger: Undefined behavior (#2284)
* build:
    * Build issues in older clang versions (#2270, #2279, #2280)
@patrick96 patrick96 mentioned this issue Dec 12, 2020
12 tasks
@pawel-szopinski
Copy link
pawel-szopinski commented Dec 12, 2020

@patrick96 big thanks for the quick fix! I can confirm it is indeed resolved in 3.5.1.

@apetresc
Copy link
Author
apetresc commented Apr 6, 2021

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants
0