Unix/Linux Go Back    


Shell Programming and Scripting BSD, Linux, and UNIX shell scripting Post awk, bash, csh, ksh, perl, php, python, sed, sh, shell scripts, and other shell scripting languages questions here.

Kill the running program

Shell Programming and Scripting


Closed    
 
Thread Tools Search this Thread Display Modes
    #1  
Old Unix and Linux 12-26-2008
akhtar.bhat akhtar.bhat is offline
Registered User
 
Join Date: Nov 2008
Last Activity: 2 November 2009, 2:28 AM EST
Posts: 19
Thanks: 0
Thanked 0 Times in 0 Posts
Unix or Linux Question Kill the running program

Dear All,

I have a script which after executing is not stoping when i press ctrl+c.
Now i want to Append the script in such a way when i press ctrl+c while execution of the program it should take it as arguements and should kill the script/running program forcefully.

I know the command to kill the the program Forcefully (kill -9 `ps -a | grep "ping_script" | awk '{print $1}'` )


Please help me to get out of this problem.
Advance Thanks,
Akhtar Bhat.
Sponsored Links
    #2  
Old Unix and Linux 12-26-2008
matrixmadhan matrixmadhan is offline Forum Advisor  
Technorati Master
 
Join Date: Mar 2005
Last Activity: 3 October 2016, 6:30 AM EDT
Location: classification algos
Posts: 3,206
Thanks: 19
Thanked 30 Times in 27 Posts
Here is an example to trap INT signal ( Ctrl - C )


Code:
signal()
{
  echo "-- signal() --"
  echo "sleeping"
  sleep 1
  exit
}

trap signal INT

while :
do
  echo "here"
  sleep 1
done

Sponsored Links
Closed

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Linux More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
Trying to kill a program via help command. TiznaraN Shell Programming and Scripting 5 04-22-2008 01:57 PM
kill multiple instances of the same program ipzig Shell Programming and Scripting 12 12-17-2007 02:42 AM
kill textrdit program jeter Programming 6 06-07-2006 10:12 AM
C program to kill root processes TioTony Programming 8 07-25-2003 12:16 AM



All times are GMT -4. The time now is 12:14 PM.