I'm currently testing a C++ program on the command line of a linux machine and unfortunately it sometimes gets into infinite loops. Is there a way that, from the command line, I can kill this program?
7 Answers
ps aux | grep "name of program" | cut -d ' ' -f 2 | xargs kill -9
is a nice oneliner for this.
ps -aux | grep "name of the program"
will give you the id of the program and then:
kill -9 <id of the programm>
Use the ps
command to learn the PID of your program's process, then kill
to terminate the process.
-
How can I run these commands while my program is still looping? Commented Feb 19, 2012 at 21:09
-
You can use control-Z to put your program in the background. But really, you should always have more than one shell when you're doing "real work" on a text-based interface. What if you need to look at one piece of code while you edit another? Commented Feb 19, 2012 at 21:37