|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
AT&T devCentral & BlackBerry(r) Webcast Series: BlackBerry and GPS -Build Location Awareness into your BlackBerry Applications, July 10th-1:00PM EST. Register Today!
|
|
#1
|
|||
|
|||
|
Orphaned sleep processes
Hi All,
I'm running a ksh script that runs a background process that spends most of its time in the sleep command. When I list the processes I can see my main script, with the background script listed as a child process, and the sleep listed as a child of that. When my main script kills the background script it leaves the sleep process running but sets it parent process ID to 1, effectively orphaning the sleep. Does anyone know of a way of making sure that the sleep is killed when its parent is killed? Thanks Steve |
|
#2
|
|||
|
|||
|
Those sleep processes become owned by init and init will clean them up when they exit.
But here is something to try. In the main script turn on job control: set -o monitor Capture the pid of the background process. /path/to/other_script & pid=$! When you want to kill the background script together with those sleep processes use the syntax: kill -15 -${pid} For this to work, that background script must not also turn on monitor mode. And your OS must support posix style process groups. |
|
#3
|
|||
|
|||
|
Hmm ... can't seem to get that to work.
The kill reports "The specified process does not exist". From looking at the man page, it seems that it's expecting a negative process ID to actually be a process group ID: Quote:
Never mind. Those sleep processes aren't doing any harm other than taking up an entry in the process table. I'll leave them alone until inspiration strikes. ![]() Thanks anyway. Steve |
|
#4
|
|||
|
|||
|
That's right, you need to hit a process group. The process group is is the pid of the process group leader. And this doesn't change even if the process group leader exits. I just tried this with a simple script called sleeper:
#! /usr/bin/ksh sleep 60 & sleep 60 & sleep 60 & sleep 15 exit 0 And this script: #! /usr/bin/ksh set -o monitor ./sleeper & pid=$! echo pid = $pid kill -15 -${pid} ps -f exit 0 And it works for me on HP-UX and SunOS. |
|
#5
|
|||
|
|||
|
When I tried that script on my AIX 5.2 box ... it worked perfectly as well. And the technique worked when I re-applied it to my larger script! I must have fouled something up on the first attempt. Fat fingers causing trouble I guess.
Many thanks. Steve |
![]() |
| Viewing: Dev Shed Forums > Operating Systems > UNIX Help > Orphaned sleep processes |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|