Tag Archives: PID

Get process id:

tasklist

C:\Users\Joel>tasklist

Image Name                     PID Session Name        Session#    Mem Usage
========================= ======== ================ =========== ============
System Idle Process              0 Services                   0          4 K
System                           4 Services                   0      4,028 K
smss.exe                       308 Services                   0        332 K
csrss.exe                      440 Services                   0      2,580 K
wininit.exe                    516 Services                   0        688 K
services.exe                   612 Services                   0      4,728 K
.....
Acrobat.exe                   5876 Console                    3     63,964 K
chrome.exe                    3668 Console                    3    128,464 K

Now, trying to kill Acrobat forcefully:
C:\Users\Joel>taskkill /PID 5876 /F
ERROR: The process with PID 5876 could not be terminated.
Reason: There is no running instance of the task.

Retrying with /T option (kill all child processes too):

C:\Windows\system32>taskkill /PID 5876 /T
SUCCESS: Sent termination signal to process with PID 4808, child of PID 7728.
ERROR: The process with PID 7728 (child process of PID 5876) could not be termin
ated.
Reason: This process can only be terminated forcefully (with /F option).
ERROR: The process with PID 5876 (child process of PID 1532) could not be termin
ated.
Reason: One or more child processes of this process were still running.

C:\Windows\system32>

Now even though it showed an error, the process was terminated.

Recently I was running Unetbootin to install a live dvd image on a pen drive. It got stuck in the middle of the job, and even after closing it, I couldnt umount it with umount or gparted. It was suggested that I use fuser or lsob to identify and terminate the running process.

Gparted showed me that the drive was the device /dev/sdc1

So I tried to identify the process using the device

$ ps ax | grep '/media/D514-D264'
20291 ? D 0:09 /usr/lib/p7zip/7z -bd -aos -o/media/D514-D264 e /userhome/CD Images/livedvd-x86-amd64-32ul-2012.1.iso image.squashfs
21055 ? D 0:05 /usr/lib/p7zip/7z -bd -aos -o/media/D514-D264 e /userhome/CD Images/livedvd-x86-amd64-32ul-2012.1.iso image.squashfs
22896 pts/4 S+ 0:00 grep --color=auto /media/D514-D264[/code]

The integer displayed on lefthand coloumn is the PID (processid)

The command kill can be used to stop the process, by specifying the kill signal and process id.

Table 12-2. Common kill signals

Signal name Signal value Effect
SIGHUP 1 Hangup
SIGINT 2 Interrupt from keyboard
SIGKILL 9 Kill signal
SIGTERM 15 Termination signal
SIGSTOP 17,19,23 Stop the process

So to kill (signal 9) processes 20291,21055,22896 I would issue the command:

[[email protected] c]$ sudo kill -9 21055
[[email protected] c]$ sudo kill -9 22896
kill: No such process
[[email protected] c]$ ps ax | grep '/media/D514-D264'
[/code]

There, no more running processes using the device. Voila, now gparted has no problem unmounting the device!