Kill the running program | Unix Linux Forums | Shell Programming and Scripting

  Go Back    


Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts and shell scripting languages here.

Kill the running program

Shell Programming and Scripting


Closed Thread    
 
Thread Tools Search this Thread Display Modes
    #1  
Old 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
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 12-26-2008
matrixmadhan matrixmadhan is offline Forum Advisor  
Technorati Master
 
Join Date: Mar 2005
Last Activity: 5 July 2014, 11:14 AM EDT
Location: classification algos
Posts: 3,203
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

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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
Kill Processes Running On a Particular Port mahatma UNIX for Advanced & Expert Users 7 03-20-2006 07:50 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 05:44 AM.