[clug] Launch gnome-terminal to launch daemon process

David Deaves David.Deaves at dd.id.au
Tue Aug 25 04:54:53 UTC 2015


> Runs fine if you just run it from a terminal. No different in input or
> output so I'd agree that's unlikely to be a cause.
> 
> This:
> 
> trap "date > /tmp/signal-test" INT HUP QUIT TERM
> cmd="exec /usr/bin/python /opt/ark/bin/hgview &"
> eval $cmd
> 
> also didn't make any difference which makes sense to me as the scrip
> will exit very quickly after launching the python so won't be around
> to trap the signals.
> 

However that is not quiet the same.  The special case of

trap '' 1

is setting the handler to SIG_IGN  (signal ignore), a property inherited by 
children.  When you put a shell command to run in there, it no longer makes 
sense for a child to inherit that, I suspect that children then inherit 
SIG_DFL (default which for SIGHUP is exit).

With this simple setup:

[dave at rimmer ~]$ cat /tmp/piss_phart 
#!/bin/bash

trap '' 1

#trap "date > /tmp/signal-test" INT HUP QUIT TERM

sleep 12345678 &

[dave at rimmer ~]$ xterm -e '/tmp/piss_phart'

An xterm appears, and both sleeps are shown by ps
after 12 seconds the xterm disappears, but the sleep 12345678 is still running.

The other possibility is that python is returning the signal handlers to 
default, in which case you python program will need to perform the equivalent 
of the 'trap' command.

You may want to try running  strace  on your python to see why it is dying.  
For comparison strace against my sleep command shows this when the xterm dies.


[dave at rimmer2 ~]$ strace -p 5921
Process 5921 attached - interrupt to quit
restart_syscall(<... resuming interrupted call ...>
#### When xterm dies this comes up - 
                                                   ) = ? ERESTART_RESTARTBLOCK (To be restarted)
--- {si_signo=SIGHUP, si_code=SI_KERNEL, si_value={int=382268158, ptr=0x3616c8f2fe}} (Hangup) ---
restart_syscall(<... resuming interrupted call ...>




> 
> 
> 
> On 25 August 2015 at 13:18, David Deaves <David.Deaves at dd.id.au> wrote:
> >
> >
> > Most likely method causing your python to exit when the shell does is it
> > receiving a SIGHUP when the terminal exits.  You should be able to handle this
> > by adding this command before the python command
> >
> > trap '' 1
> >
> > may even want to ignore SIGINT also so
> >
> > trap '' 1 2
> >
> >
> > Another possibility is some IO to the pseudo terminal now failing when it
> > goes away - this is less likely to be your issue and normally has the opposite
> > effect, calling programs don't exit/carry on until the child program exits.
> >
> > exec <&-   #  Will close STDIN
> > exec >&- 2>&-  # Will close STDOUT - though as you want to see errors from python you probably don't want this
> >
> >
> > Dave !
> >
> >
> >
> >
> >





More information about the linux mailing list