LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   Killing a background process (https://www.linuxquestions.org/questions/linux-newbie-8/killing-a-background-process-659216/)

arun_nishad 07-30-2008 05:17 AM

Killing a background process
 
I have a shell script:

#!/bin/sh
./hello.sh >> /tmp/x &
tail -f /tmp/x
exit 0

when i do Ctrl-c
tail -f /tmp/x killed
hello.sh does not kill.
How to kill this background process using Ctrl-c ?

chrism01 07-30-2008 05:25 AM

Ctrl-C kills the current foreground process. If you want to kill a backgrounded process, either
1. don't background it
Or
2. get the pid and kill that eg

Code:

./hello.sh >> /tmp/x &
bg_pid=$!
kill $bg_pid

See http://www.tldp.org/LDP/abs/html/refcards.html#AEN20710


All times are GMT -5. The time now is 08:20 AM.