Re: (kill -1 $$)

From: John DuBois (spcecdt_at_armory.com)
Date: 11/30/04


Date: 29 Nov 2004 23:23:59 GMT

In article <87brdhwl5l.fsf@jidanni.org>,
Dan Jacobson <jidanni@jidanni.org> wrote:
>Why does this script print 3? [bash]
>echo 1 $$;(echo 2 $$; kill -1 $$; echo 3); echo 4
>1 8360
>2 8360
>3
>Hangup
>I would have thought it would print 4, not 3.
>Is the only way to stop the subshell "exit"?

The value of $$ does not change when you fork a subshell with (). Yes, it
seems odd, but that's the defined behavior: it's the PID of the last *exec'ed*
shell in the process' ancestry, not the last *forked* shell. If you did get
the subshell's pid (with a little more work), then yes, a signal 1 would kill
it.

        John

-- 
John DuBois  spcecdt@armory.com  KC6QKZ/AE  http://www.armory.com/~spcecdt/


Relevant Pages

  • PID of subshell forked with ()
    ... > Yes, it seems odd, but that's the defined behavior: ... > more work), then yes, a signal 1 would kill it. ... PID of the subshell I'm in? ...
    (comp.unix.shell)
  • Re: pid from startet process
    ... perl script and need to know the childs pid. ... but the pid i am getting is not right. ... That shell then creates a new process to ... execute the command named in the $cmd parameter. ...
    (comp.lang.perl.misc)
  • Re: External Unix programme - time limit
    ... checking if the process is still active after the sleep. ... >> kill the right programme...and when using the syntax you ... > You don't need to know the PID, %1 is the first job running in the ... > shell, which should be your ./senkin.e program. ...
    (comp.soft-sys.matlab)
  • Re: Executing a command in sub-shell
    ... > script and only 1 line of output, ... which is expanded by the shell where it has not been set. ... > expand it dynamically in the subshell, it needs to be quoted in the here ... > its parent shell, so you're out of luck there. ...
    (comp.unix.shell)
  • Re: PID of exec
    ... but it contained the same PID as the "my $pid=fork" statment. ... noticed that you tried to write the pid out after the exec. ... array with one element in it, the argument is checked for shell ... If there are no shell metacharacters in the argument, ...
    (comp.lang.perl.misc)