LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Server
User Name
Password
Linux - Server This forum is for the discussion of Linux Software used in a server related context.

Notices



Reply
 
Search this Thread
Old 07-18-2011, 08:22 AM   #1
carlosOFF
LQ Newbie
 
Registered: Dec 2010
Posts: 11

Rep: Reputation: 0
Question kill a running process


Hello everybody,

I trying to kill one process but only if the process is running, what I tried to do was that:

list=`ps x | grep crttool | grep -v grep | awk '{print $1,$3}'`

With that I can retrieve the pid and the status, but for every process in one string.

Who could I see if the status is running (R) and kill it.

There's a way to send the awk exit to one array? or a better way?

thank's
Carlos
 
Old 07-18-2011, 10:21 AM   #2
MTK358
LQ 5k Club
 
Registered: Sep 2009
Posts: 6,443
Blog Entries: 3

Rep: Reputation: 714Reputation: 714Reputation: 714Reputation: 714Reputation: 714Reputation: 714Reputation: 714
What does "exit to one array" mean?

Ayway, what's wrong with "killall"?

Code:
killall crttool
Also, it's better to use $(command) instead of backticks. It nests easily and can't be confused with single quotes.
 
Old 07-19-2011, 08:33 AM   #3
carlosOFF
LQ Newbie
 
Registered: Dec 2010
Posts: 11

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by MTK358 View Post
What does "exit to one array" mean?

Ayway, what's wrong with "killall"?

Code:
killall crttool
Also, it's better to use $(command) instead of backticks. It nests easily and can't be confused with single quotes.

I can't do that, because the problem is if the process is running, i could figure out the solution, by doing this:

toKill=`ps x | grep process | grep -v grep | awk '/R/ {print $1}'`

the problem is that process is running like a ghost the application is closed but still running.
It's a TCL application

Thanks!
Carlos
 
Old 07-19-2011, 09:00 AM   #4
colucix
Moderator
 
Registered: Sep 2003
Location: Bologna
Distribution: CentOS 6.5 OpenSuSE 12.3
Posts: 10,509

Rep: Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957Reputation: 1957
This lists the processes and kill them:
Code:
ps -C command -o pid,state --no-headers | awk '/S/{print "kill -9", $1 | "/bin/bash"}'
 
Old 07-19-2011, 12:37 PM   #5
Reuti
Senior Member
 
Registered: Dec 2004
Location: Marburg, Germany
Distribution: openSUSE 13.1
Posts: 1,320

Rep: Reputation: 252Reputation: 252Reputation: 252
Quote:
Originally Posted by colucix View Post
This lists the processes and kill them:
Code:
ps -C command -o pid,state --no-headers | awk '/S/{print "kill -9", $1 | "/bin/bash"}'
I think it can be shortened by a system calll:
Code:
system("kill -9 " $1)
(note the space behing -9). Any reason why you chose /S/ and not /R/?
 
1 members found this post helpful.
  


Reply

Tags
awk, kill, process


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
kill an running application process inside windows XP nano2 Programming 1 09-22-2009 03:12 PM
bash `kill`: process 'B' silently dies; but process 'A' = `kill` spews back debris! GrapefruiTgirl Programming 9 06-23-2009 10:42 AM
Shell Script : Kill a running process when another process starts ashmew2 Linux - General 3 08-20-2008 04:47 AM
Can kernel kill long-running process? registering Linux - Kernel 5 07-20-2007 09:45 AM
How can I see what process are running and how to I kill them? (command line). brynjarh Linux - Newbie 4 07-07-2004 04:01 PM


All times are GMT -5. The time now is 12:09 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration