Re: (kill -1 $$)
From: Stephen Riehm (stephen.riehm_at_gmx.net)
Date: 11/30/04
- Next message: laura fairhead: "Re: unix command to tell what is the current shell"
- Previous message: Spam Killer: "Re: Access permissions"
- In reply to: John DuBois: "Re: (kill -1 $$)"
- Next in thread: Villy Kruse: "Re: (kill -1 $$)"
- Reply: Villy Kruse: "Re: (kill -1 $$)"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Tue, 30 Nov 2004 01:49:40 +0100
John DuBois wrote:
> 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
How bizarre!
Even this doesn't work:
--- start
sh
cat << _EOF_ > ./suicidal_script.sh
#!/bin/sh
echo 2 $$
kill -1 $$
echo 3
_EOF_
chmod +x ./suicidal_script.sh
echo 1 $$; ./suicidal_script.sh; echo 4
--- end
Doing this I got:
1 639
2 639
3
Hangup
Exit 129
(and the shell started on the first line was killed!)
Note: sh is actually bash, if that makes any difference.
I would have at least expected a script started by the shell to run in a
NEW process, and a fresh view of the world (as far as $$ is concerned).
Strangely the original test works as Dan expected in ksh on OS-X!!
(available at www.kornshell.com)
Steve
(Sorry, no answer this time, just more confusion)
- Next message: laura fairhead: "Re: unix command to tell what is the current shell"
- Previous message: Spam Killer: "Re: Access permissions"
- In reply to: John DuBois: "Re: (kill -1 $$)"
- Next in thread: Villy Kruse: "Re: (kill -1 $$)"
- Reply: Villy Kruse: "Re: (kill -1 $$)"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|