Why can't I kill the shell using the PID obtained from the $$ special variable?
Solution 1
You can, but the shell tries hard not to die unless it's absolutely sure that's what is required.
SIGHUP works (as does SIGKILL), and you can try this -
kill -HUP $$
(If you prefer numeric signal identifiers the HUP
can be replaced with 1
.)
The reason that SIGHUP
works is that this is the signal that would have been sent when a serial line connection over a modem was terminated - for instance if the phone line was hung up.
Solution 2
Check the bash manual:
When bash is interactive, in the absence of any traps, it ignores SIGTERM
https://www.gnu.org/software/bash/manual/bashref.html#Signals
Check the kill
help text (help kill
at a bash prompt):
If neither SIGSPEC nor SIGNUM is present, then SIGTERM is assumed.
https://www.gnu.org/software/bash/manual/bashref.html#index-kill
Related videos on Youtube
Abdul Al Hazred
Updated on September 18, 2022Comments
-
Abdul Al Hazred almost 2 years
After I have learned that the
$$
special variable holds the process number of the shell, I tried too kill the shell by simply:kill <pid obtained by echo $$>
, however this did not work, I also tried some variations, but them also had no effect.-
Leiaz over 9 yearsxargs is totally overkill here. Just use
kill $$
(although it won't work, as explained in link above). And you should copy paste the text instead of posting a screenshot. -
Abdul Al Hazred over 9 yearsI wanted to copy paste first, but once I tried , I got a total unformatted character mess.
-
jasonwryan over 9 yearsAs with every one of your other questions, this one exhibits no effort to search: either for previous questions or how to format text on the site. Please stop being such a help vampire.
-