Re: (kill -1 $$)
From: John DuBois (spcecdt_at_armory.com)
Date: 11/30/04
- Next message: John W. Krahn: "Re: how to use sed to replace a single occurrence in a file"
- Previous message: Chris F.A. Johnson: "Re: How to use same variable in different scripts"
- In reply to: Dan Jacobson: "(kill -1 $$)"
- Next in thread: Stephen Riehm: "Re: (kill -1 $$)"
- Reply: Stephen Riehm: "Re: (kill -1 $$)"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
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/
- Next message: John W. Krahn: "Re: how to use sed to replace a single occurrence in a file"
- Previous message: Chris F.A. Johnson: "Re: How to use same variable in different scripts"
- In reply to: Dan Jacobson: "(kill -1 $$)"
- Next in thread: Stephen Riehm: "Re: (kill -1 $$)"
- Reply: Stephen Riehm: "Re: (kill -1 $$)"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|