Gentoo Forums
Gentoo Forums
Gentoo Forums
Quick Search: in
Script behaviour that is attached to init at master exit
View unanswered posts
View posts from last 24 hours

 
Reply to topic    Gentoo Forums Forum Index Portage & Programming
View previous topic :: View next topic  
Author Message
Dominique_71
Veteran
Veteran


Joined: 17 Aug 2005
Posts: 1897
Location: Switzerland (Romandie)

PostPosted: Sun Jan 26, 2025 6:02 pm    Post subject: Script behaviour that is attached to init at master exit Reply with quote

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
View user's profile Send private message
sublogic
Guru
Guru


Joined: 21 Mar 2022
Posts: 303
Location: Pennsylvania, USA

PostPosted: Mon Jan 27, 2025 2:56 am    Post subject: Re: Script behaviour that is attached to init at master exit Reply with quote

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
View user's profile Send private message
Display posts from previous:   
Reply to topic    Gentoo Forums Forum Index Portage & Programming All times are GMT
Page 1 of 1

 
Jump to:  
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