I am running a program in the terminal that I can't escape with Ctrl-C and that I want to kill. How can I find its PID?
|
|
Open another terminal and run
The first field of each line of output is a number which represents the Process ID of the program matched by To halt the offending process, do:
If you are running a graphical interface, of course, you don't have to fool with this crazy command-line stuff to get the job done. Just open "System Monitor", navigate to the Processes tab, choose the process you want to halt (Hm, could it be the one using 90% CPU?) and right-click it. Since the process is already stopped, (that's the problem, right?) choose End Process or Kill Process from the resulting menu.
|
|||||
|
|
I don't think there is any need of such long commands when you can accomplish the same commands with pgrep, pkill, pidof etc...
pgrep:
DESCRIPTION : pgrep looks through the currently running processes and lists the process IDs which match the selection criteria to stdout. All the criteria have to match. For example,
pidof: DESCRIPTION: Pidof finds the process id's (pids) of the named programs. It prints those id's on the standard output. syntax: pidof program_name
|
||||
|
|
|
The easiest way to know the pid of a running program is using:
For example, if you started vim and want to know its pid:
Remember that you will need to provide the exact program name that has been started. For example, if you are running vi and execute Refer to |
|||||
|
|
I have found it is nice to use a case insensitive search by adding the "-i" and using "aux" instead of "ax" to get a more descriptive output:
If you would like to kill all the processes you may use:
That is a forceful kill. Drop the "-9" if you want a soft kill. |
|||||||||||||
|
|
If you want only the pid (useful for autokill scripts, etc...)
|
|||
|
|
|
You can also open another terminal (or switch to another tty) and run |
|||
|
|
|
You could do:
first two pipes get process info, next we try to get PID column by using the old-school cut and then we give the resulting PID to kill. |
|||||||||
|
|
For those running Ubuntu 16.04 LTS, you must use |
|||
|
|