[SunHELP] for loop changes nohup?
Richard Russell
richard.russell at db.com
Mon Nov 22 10:07:42 CST 2004
I've simplified this further:
In one terminal (pts/17), I run `sleep 20`, then the following in the
second terminal (pts/12):
------------------------------------------------
$USER@$HOST:$HOME > ps -ju $USER
PID PGID SID TTY TIME CMD
10992 10992 10992 pts/12 0:00 ksh
19546 19546 20078 pts/17 0:00 sleep
20078 20078 20078 pts/17 0:01 ksh
$USER@$HOST:$HOME > psig 19546 > direct
------------------------------------------------
Then, the same thing , but running `for i in one; do sleep 20; done` in
the first terminal:
------------------------------------------------
$USER@$HOST:$HOME > ps -ju $USER
PID PGID SID TTY TIME CMD
10992 10992 10992 pts/12 0:00 ksh
20585 20078 20078 pts/17 0:00 sleep
20078 20078 20078 pts/17 0:01 ksh
$USER@$HOST:$HOME > psig 20585 > loop
$USER@$HOST:$HOME > diff direct loop
1c1
< 19546: sleep 20
---
> 20585: sleep 20
25c25
< TSTP default
---
> TSTP ignored
27,28c27,28
< TTIN default
< TTOU default
---
> TTIN ignored
> TTOU ignored
------------------------------------------------
Again, I would have expected this to work the other way around, if it was
different at all. Does anyone have any references that could explain this
behaviour? (the fact that a the for loop starts processes in the same
proces group, wheres starting the process directly starts it in a new
group?)
Cheers
Richard Russell
Deutsche Bank AG London
Global Markets Customer Solutions
Office: +44 (0)20 7545 8060
Mobile: +44 (0)79 0661 2237
"Richard Russell" <richard.russell+external at db.com>
Sent by: sunhelp-bounces at sunhelp.org
11/22/2004 03:42 PM
Please respond to The SunHELP List
To: The SunHELP List <sunhelp at sunhelp.org>
cc:
Subject: RE: [SunHELP] for loop changes nohup?
OK, looks promising...
`./start`:
----
> ps -ju $USER
PID PGID SID TTY TIME CMD
16402 16400 20078 pts/17 0:01 java
20078 20078 20078 pts/17 0:00 ksh
----
`for i in one; do ./start; done`
----
> ps -ju $USER
PID PGID SID TTY TIME CMD
11703 20078 20078 pts/17 0:01 java
20078 20078 20078 pts/17 0:00 ksh
----
... But why would a for loop start the process in the same group, whereas
the original command does it in a new group?
FYI I also discovered the psig command, ran it on the direct (./start) and
in_loop (for i in ...) processes, and diff'd the output:
----
> diff direct in_loop
1c1
< 10939: $JAVAHOME/bin/../bin/sparc/native_threads/java -
---
> 11703: $JAVAHOME/bin/../bin/sparc/native_threads/java -
25c25
< TSTP default
---
> TSTP ignored
27,28c27,28
< TTIN default
< TTOU default
---
> TTIN ignored
> TTOU ignored
---
Again, I fail to understand why the in_loop one would have different
responses to signals cf the direct one, and even here, it appears to
ignore more signals -- which seems opposite of what I expect given the
behaviour...
Richard Russell
Deutsche Bank AG London
Global Markets Customer Solutions
Office: +44 (0)20 7545 8060
Mobile: +44 (0)79 0661 2237
DAUBIGNE Sebastien - BOR <sebastien.daubigne at atosorigin.com>
Sent by: sunhelp-bounces at sunhelp.org
11/22/2004 03:14 PM
Please respond to The SunHELP List
To: The SunHELP List <sunhelp at sunhelp.org>
cc:
Subject: RE: [SunHELP] for loop changes nohup?
Here are some SIGHUP rules from
http://www.faqs.org/faqs/unix-faq/programmer/faq/.
I guess your problem is related to process group management (sh will
launch
the command in the same process group as the parent, as ksh will create a
separate process group).
Maybe you could send us the result from 'ps -ju $USER' which will print
session/process group leaders to help understand.
1.15 Why doesn't my process get SIGHUP when its parent dies?
============================================================
Because it's not supposed to.
`SIGHUP' is a signal that means, by convention, "the terminal line got
hung
up". It has nothing to do with parent processes, and is usually generated
by the tty driver (and delivered to the foreground process group).
However, as part of the session management system, there are exactly two
cases where `SIGHUP' is sent on the death of a process:
* When the process that dies is the session leader of a session that is
attached to a terminal device, `SIGHUP' is sent to all processes in
the foreground process group of that terminal device.
* When the death of a process causes a process group to become
orphaned,
and one or more processes in the orphaned group are *stopped*, then
`SIGHUP' and `SIGCONT' are sent to all members of the orphaned group.
(An orphaned process group is one where no process in the group has a
parent which is part of the same session, but not the same process
group.)
--
Sebastien DAUBIGNE
Sebastien.daubigne at atosorigin.com <
mailto:Sebastien.daubigne at atosorigin.com>
- +33(0)5.57.26.56.36
AtosOrigin Infogerance - IMS/ERP/Pessac
-----Message d'origine-----
De : sunhelp-bounces at sunhelp.org [mailto:sunhelp-bounces at sunhelp.org]De
la part de Richard Russell
Envoyi : lundi 22 novembre 2004 15:30
@ : The SunHELP List
Objet : Re: [SunHELP] for loop changes nohup?
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
_______________________________________________
SunHELP maillist - SunHELP at sunhelp.org
http://www.sunhelp.org/mailman/listinfo/sunhelp
_______________________________________________
SunHELP maillist - SunHELP at sunhelp.org
http://www.sunhelp.org/mailman/listinfo/sunhelp
_______________________________________________
SunHELP maillist - SunHELP at sunhelp.org
http://www.sunhelp.org/mailman/listinfo/sunhelp
More information about the SunHELP
mailing list