For example,
#!/bin/bash
while :
do
sl
done
How to terminate this bash script?
The program If you try this, you'll notice that you can stop each individual
|
|||||||||
|
The You can also specify jobs by number or by name. e.g. when you suspend a job with ^Z, bash will tell you what its job number is with something like For more info on job control and on killing jobs, run e.g. $ ./killme.sh ./killme.sh: line 4: sl: command not found ./killme.sh: line 4: sl: command not found ./killme.sh: line 4: sl: command not found ./killme.sh: line 4: sl: command not found ./killme.sh: line 4: sl: command not found ... ... ... ./killme.sh: line 4: sl: command not found ^Z [1]+ Stopped ./killme.sh $ kill %% $ [1]+ Terminated ./killme.sh In this example, the job's number was 1, so (NOTE: I don't have |
|||||||||||||||||
|
You can terminate that script by pressing Ctrl+C from terminal where you started this script. Of course this script must run in foreground so you are able to stop it by Ctrl+C. Or you can find PID (Process ID) of that script in other opened terminal by:
Both ways should do the trick your are asking for. |
|||||
|
You can |
||||
|
this should help. |
|||||
|
ctrl-c
to send theSIGINT
signal (in most shells) or you can pressctrl-z
that sends theSIGTSTP
signal (in most shells). In the case you pressedctrl-z
the related process isn't killed but paused. You can resume it withfg
(at least inbash
) – user1146332 Sep 17 '12 at 15:59sl
command which I believe is an annoing command for those who misspellls
, showing a train passing slowly by. As far as I know it traps theSIGINT
signal and must be killed withSIGKILL
. – Herman Torjussen Sep 17 '12 at 16:48