[SunHELP] for loop changes nohup?
Richard Russell
richard.russell at db.com
Mon Nov 22 08:30:12 CST 2004
OK, that makes a little more sense to me... but I can't see any difference
in the output of ptree, or in the ppid using ps... (again, with $USER,
$HOST, $HOME and $PATHTOJAVA replaced). Note that the scripts terminate
immediately after starting the java process, which again, makes me wonder
where the SIGTERM (or whichever SIG it is) is coming from... ie the
processes marked in braces ([]) terminate after starting the java process:
./start: ...
ksh [ --> sh --> nohup --> ksh --> nohup & --> ] java
for i in one; do ./start; done ...
ksh [ ( --> ksh subshell ) --> sh --> nohup --> ksh --> nohup & --> ] java
Here's some output of ptree and ps -o ppid,pid,args for each situation.
You can see that the parent PID of the java process is init...
----
$USER@$HOST:$HOME > ptree -a $USER
1 /etc/init -
3182 /usr/sbin/sshd
21419 /usr/sbin/sshd
21433 -ksh
14482 ptree -a $USER
$USER@$HOST:$HOME > ./start
+ nohup $HOME/start2
Sending output to nohup.out
$USER@$HOST:$HOME > ptree -a $USER
1 /etc/init -
3182 /usr/sbin/sshd
21419 /usr/sbin/sshd
21433 -ksh
14667 ptree -a $USER
14566 $PATHTOJAVA/bin/../bin/sparc/native_threads/java -cp . Slee
$USER@$HOST:$HOME > ps -p 14566 -o ppid,pid,args
PPID PID COMMAND
1 14566 $PATHTOJAVA/bin/../bin/sparc/native_threads/java -cp . Slee
$USER@$HOST:$HOME > ll ps -p 14566 -o ppid,pid,args
$USER@$HOST:$HOME > kill 14566
$USER@$HOST:$HOME > ptree -a $USER
1 /etc/init -
3182 /usr/sbin/sshd
21419 /usr/sbin/sshd
21433 -ksh
16682 ptree -a $USER
$USER@$HOST:$HOME > for i in 1; do ./start; done
+ nohup $HOME/start2
Sending output to nohup.out
$USER@$HOST:$HOME > ptree -a $USER
1 /etc/init -
3182 /usr/sbin/sshd
21419 /usr/sbin/sshd
21433 -ksh
16919 ptree -a $USER
16826 $PATHTOJAVA/bin/../bin/sparc/native_threads/java -cp . Slee
$USER@$HOST:$HOME > ps -p 16826 -o ppid,pid,args
PPID PID COMMAND
1 16826 $PATHTOJAVA/bin/../bin/sparc/native_threads/java -cp . Slee
$USER@$HOST:$HOME > kill 16826
$USER@$HOST:$HOME > ptree -a $USER
1 /etc/init -
3182 /usr/sbin/sshd
21419 /usr/sbin/sshd
21433 -ksh
17667 ptree -a $USER
----
Hence, I don't think that the signal is coming from the parent process. In
fact, I have a feeling that it has more to do with the terminal (eg
pts/26) closing than a signal... does closing a tty send signals anywhere?
Even if it does, it still doesn't explain why the for loop changes
anything... I have also tried adding output redirects on to the process,
but to no avail:
----
$USER@$HOST:$HOME
> more start2
#!/bin/ksh -x
nohup /data/fiplu1/users/tpuat11/java/bin/java -cp . Sleep 2>&1 >
/dev/null &
----
So, I'm still baffled...
Richard Russell
Deutsche Bank AG London
Global Markets Customer Solutions
Office: +44 (0)20 7545 8060
Mobile: +44 (0)79 0661 2237
velociraptor <velociraptor at gmail.com>
Sent by: sunhelp-bounces at sunhelp.org
11/22/2004 01:54 PM
Please respond to velociraptor; Please respond to The SunHELP List
To: The SunHELP List <sunhelp at sunhelp.org>
cc:
Subject: Re: [SunHELP] for loop changes nohup?
On Mon, 22 Nov 2004 10:33:14 +0000, Richard Russell
<richard.russell at db.com> wrote:
> Thanks -- my immediate thought on this is that it could explain the
> opposite behaviour more likely than what I actually see...
>
> ie you're suggesting this:
>
> ./start: ...
> ksh --> sh --> nohup --> ksh --> nohup & --> java
>
> for i in one; do ./start; done ...
> ksh ( --> ksh subshell ) --> sh --> nohup --> ksh --> nohup & --> java
>
> Why would exiting the ksh from the for loop example be more likely to
> cause the java process to exit than it would in the first example?
> Certainly, I would have expected that the nohup would catch the signals
> anyway, so a change at this point shouldn't affect the java process, but
> why would adding a subshell affect it?
>
> Then again, I've never really understood how signals propagate...
>
> Does anyone have any other ideas?
I think what Sheldon was implying that if the for loop is run in a
subshell,
any process spawned by that subshell will die when the parent pid dies.
So, when the for loop exits, it's child processes die as well. The
question
is, what signal does the shell send with it exits?
According to the man page, nohup only causes processes to ignore
SIGHUP and SIGQUIT. If you background the process it also ignores
interrupts. It doesn't prevent a SIGTERM from working.
I'd think you could test this by:
log in
log in from a second terminal
from within the first login shell:
run another shell process
then start your nohup script
in the second terminal:
do a ptree on the script
kill the pid of the login shell of your initial terminal session
But that still doesn't really test what signal is sent by a script's
subshell
exiting; I think you'll have to read up on ksh/sh.
What's the standard method for starting a process without it being a
child of the current process? Can you even do it from within a shell
script?
Regards--
=Nadine=
_______________________________________________
SunHELP maillist - SunHELP at sunhelp.org
http://www.sunhelp.org/mailman/listinfo/sunhelp
More information about the SunHELP
mailing list