View previous topic :: View next topic |
Author |
Message |
Dominique_71 Veteran
Joined: 17 Aug 2005 Posts: 1897 Location: Switzerland (Romandie)
|
Posted: Sun Jan 26, 2025 6:02 pm Post subject: Script behaviour that is attached to init at master exit |
|
|
My fvwm config start a few bash scripts, and when fvwm exit, one of them, instead of being killed, get lost and the system attach it to pid 1, init. That's on an openrc system.
These 3 scripts are containing a trap command with cleanup function and the same kind of loop
Code: | while :
do
sleep 5
<snip>
done |
I added a test into that while loop that call the cleanup function when 1 is found as its master pid, and it works fine. That script get now killed when fvwn exit.
That show me that the script continue to run when its master process get lost and it get attached to init. Will that be the case on all linux system? _________________ "Confirm You are a robot." - the singularity |
|
Back to top |
|
|
sublogic Guru
Joined: 21 Mar 2022 Posts: 303 Location: Pennsylvania, USA
|
Posted: Mon Jan 27, 2025 2:56 am Post subject: Re: Script behaviour that is attached to init at master exit |
|
|
Dominique_71 wrote: | That show me that the script continue to run when its master process get lost and it get attached to init. Will that be the case on all linux system? | Yes, except that a process between fvwm and you could decide to call prctl(PR_SET_CHILD_SUBREAPER, 1 ...), in which case you would be reparented to that process rather than to init.
If you are worried about such craziness, you could test for the ppid to change, rather than hard-coding "1". (That would leave you vulnerable to fvwm crashing just before your script first grabs its parent pid. Okay, test for "changed or equal to 1".) |
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
|