Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

bash: kill $$ not work?

Tags:

linux

bash

kill

The command kill $$ should kill current bash, but it seems that it doesn't work:

$ ps -p $$
  PID TTY          TIME CMD
18179 pts/4    00:00:00 bash
$ kill $$
$ ps -p $$
  PID TTY          TIME CMD
18179 pts/4    00:00:00 bash

Why?

like image 260
Yishu Fang Avatar asked Jul 10 '13 08:07

Yishu Fang


1 Answers

I'm not sure why one would like to kill the current shell. Nevertheless...

kill PID would send SIGTERM when no signal is specified. bash ignores SIGTERM and SIGQUIT in the absence of any traps.

You'll achieve the desired effect if you were to say

kill -9 $$

or

kill -SIGKILL $$

Quoting from the manual:

When Bash is interactive, in the absence of any traps, it ignores SIGTERM (so that ‘kill 0’ does not kill an interactive shell), and SIGINT is caught and handled (so that the wait builtin is interruptible). When Bash receives a SIGINT, it breaks out of any executing loops. In all cases, Bash ignores SIGQUIT.

like image 71
devnull Avatar answered Nov 16 '22 02:11

devnull