LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - General (https://www.linuxquestions.org/questions/linux-general-1/)
-   -   how to manage shutdown sequence of non-system parent/child processes ? (https://www.linuxquestions.org/questions/linux-general-1/how-to-manage-shutdown-sequence-of-non-system-parent-child-processes-4175469768/)

ErnieOnTheRun 07-16-2013 01:10 AM

how to manage shutdown sequence of non-system parent/child processes ?
 
At (unexpected ?) system shutdown, I need to GUARANTEE that for a particular parent/ child process pair (the parent can have many children), the parent is killed FIRST.

At what point in time of the shutdown process are non-system processes killed ? I initially thought, it would be the /etc/init.d/killall script, but after experimenting, I found that non-system processes are killed already BEFORE the first script from run-level 6 is executed.

My conclusion is that this can NOT be done by adding/ configuring the init scripts.

I thought the VERY FIRST thing at "shutdown" that happens, is to move the run -level to 6 and then execute the scripts/ pull down routines specified.

At which point of the shutdown process are the processes killed that are already dead when the FIRST script in /etc/rc.d/rc6.d/ is run ? How can I manage them ?

Thanks a lot in advance.

druuna 07-16-2013 02:06 AM

Quote:

Originally Posted by ErnieOnTheRun (Post 4991048)
At (unexpected ?) system shutdown, I need to GUARANTEE that for a particular parent/ child process pair (the parent can have many children), the parent is killed FIRST.

Short answer: You cannot guarantee this.

An unexpected shut-down includes, for example, a power failure or hardware failure. I do assume you're not using an UPS (or similar) or are using a system that is fault tolerant (and even then it isn't fully guaranteed).

Quote:

At what point in time of the shutdown process are non-system processes killed ? I initially thought, it would be the /etc/init.d/killall script, but after experimenting, I found that non-system processes are killed already BEFORE the first script from run-level 6 is executed.

My conclusion is that this can NOT be done by adding/ configuring the init scripts.

I thought the VERY FIRST thing at "shutdown" that happens, is to move the run -level to 6 and then execute the scripts/ pull down routines specified.

At which point of the shutdown process are the processes killed that are already dead when the FIRST script in /etc/rc.d/rc6.d/ is run ? How can I manage them ?

Thanks a lot in advance.
You are talking about RL 6, which is used for rebooting, not shutting down a linux/unix box.

Have a look at the /etc/rc0.d directory. Those scripts will shut-down your box in an orderly fashion in the order shown.

The way this is actually done differs (slightly) on different distro's.

You could add your own kill script to the appropriate rc directories, this will make sure that your process is shut down properly when issuing a normal shut-down or reboot.

This might be a good read: Learn Linux, 101: Runlevels, shutdown, and reboot

ErnieOnTheRun 07-17-2013 08:22 PM

Problem not solved by shutdown scripts in RL 0 and 6
 
Thanks, I have read the link and related documentation but the problem is not solved yet.
Let's assume a "normal shutdown" (or reboot). When I check the symlinks in /etc/rc0.d AND /etc/rc6.d, the first scripts executed are the same:
K01dnsmasq K01smartd K02avahi-daemon ....

I would LIKE to add my own shutdown script simply to the beginning of either RL 0 and/or 6, but it seems the non-system processes are ALREADY killed at this point.

I added a "ps -A" command capturing running processes BEFORE issuing the shutdown command and AT THE BEGINNING of the first script executed in RL 0 (and 6). Non-system processes (like my application) have already been killed.

Any idea when and how and why these processes are killed before the kernel moves to RL 0/ 6?

When non-system processes are killed by the OS, are they killed in any pre-determined order, like by increasing/ decreasing pid number ?

druuna 07-18-2013 01:49 AM

Which (non-system?) processes are you talking about and which Linux distro are you using?


All times are GMT -5. The time now is 11:11 AM.