[SunHELP] for loop changes nohup?

DAUBIGNE Sebastien - BOR sebastien.daubigne at atosorigin.com
Mon Nov 22 09:14:21 CST 2004


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



More information about the SunHELP mailing list