LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - General
User Name
Password
Linux - General This Linux forum is for general Linux questions and discussion.
If it is Linux Related and doesn't seem to fit in any other forum then this is the place.

Notices


Reply
  Search this Thread
Old 07-16-2013, 01:10 AM   #1
ErnieOnTheRun
LQ Newbie
 
Registered: Jul 2013
Posts: 2

Rep: Reputation: Disabled
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.
 
Old 07-16-2013, 02:06 AM   #2
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

Rep: Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405Reputation: 2405
Quote:
Originally Posted by ErnieOnTheRun View Post
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

Last edited by druuna; 07-16-2013 at 02:15 AM. Reason: Added link.
 
Old 07-17-2013, 08:22 PM   #3
ErnieOnTheRun
LQ Newbie
 
Registered: Jul 2013
Posts: 2

Original Poster
Rep: Reputation: Disabled
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 ?
 
Old 07-18-2013, 01:49 AM   #4
druuna
LQ Veteran
 
Registered: Sep 2003
Posts: 10,532
Blog Entries: 7

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


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Killing Child processes after parent has stopped C-Sniper Programming 9 05-24-2012 05:24 AM
ipc between parent and child processes using pipe rainman1985_2010 Programming 3 10-15-2010 03:30 AM
stopping both parent child processes in perl matt007 Programming 1 09-30-2009 01:46 AM
Parent child processes signal sharing iftiuk Programming 8 06-24-2004 01:32 PM
parent and child processes skora Programming 5 11-02-2003 10:41 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - General

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

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration