Killing a process with PID

Z

Zilani

Guest
To kill a process in terminal I used following commands:

to find the pid:
ps -ef |pgrep "process name"
to kill the process:
kill SIGKILL pid

Can this be done by using a single command? I was trying to do this in script
########
pid=os.system('ps -ef |pgrep "%s"'%process_name)
command=str('kill SIGKILL %s'%pid)
os.system(command)
########

But this does not work and I have found the pid was always returned 256. How can I do this? I'm new to script writing. It'll be great if anyone can explain.
 


If I know the name of the process, I may just use killall.
 
kill $(ps -ef | pgrep "process name") worked fine though I actually did not mean it. I was just trying to close a window more gently . wmctrl is what I needed . It just did fine except the Desktop. When I open my Desktop folder I find there is two window named 'Desktop'(from the list printed by "wmctrl -l" ).So wmctrl -F -c 'Desktop' does not work. Any help?
 
Make sure you aren't killing a zombie process, you can do so by executing this command

Code:
ps -Al

The output of that command should be something like this,

0 Z 1000 24589 1 0 80 0 - 0 exit ? 00:00:00 soffice.bin <defunct>

You can see that it's a zombie process by the "Z" in it. To kill the process if it isn't a zombie process, execute the following:

Code:
ps aux | awk '$8=="Z" {print $2}'
 


Top