Managing processes with the UNIX command line.

Posted: April 17, 2012. At: 11:43 AM. This was 6 years ago. Post ID: 3152
Page permalink.
WordPress uses cookies, or tiny pieces of information stored on your computer, to verify who you are. There are cookies for logged in users and for commenters. These cookies expire two weeks after they are set.

The Linux command-line has many powerful tools for viewing and managing running processes on your UNIX/Linux machine. The lsof command is a very useful command, it will display a list of all open files owned by active processes running on your system. Below is an excerpt from the output this command will give you.

[email protected]:/home/neo# lsof | tail -n 20
lsof      26891        root    4r      DIR                0,3             0     630773 /proc/26891/fd
lsof      26891        root    5w     FIFO                0,8           0t0     630778 pipe
lsof      26891        root    6r     FIFO                0,8           0t0     630779 pipe
tail      26892        root  cwd       DIR               8,53          4096     651521 /home/neo
tail      26892        root  rtd       DIR               8,49          4096          2 /
tail      26892        root  txt       REG               8,49         61864    4072509 /usr/bin/tail
tail      26892        root  mem       REG               8,49       1583120    3407895 /lib/x86_64-linux-gnu/
tail      26892        root  mem       REG               8,49        136936    3407917 /lib/x86_64-linux-gnu/
tail      26892        root  mem       REG               8,49       1534592    4079033 /usr/lib/locale/locale-archive
tail      26892        root    0r     FIFO                0,8           0t0     628464 pipe
tail      26892        root    1u      CHR              136,1           0t0          4 /dev/pts/1
tail      26892        root    2u      CHR              136,1           0t0          4 /dev/pts/1
lsof      26893        root  cwd       DIR               8,53          4096     651521 /home/neo
lsof      26893        root  rtd       DIR               8,49          4096          2 /
lsof      26893        root  txt       REG               8,49        124976    4068930 /usr/bin/lsof
lsof      26893        root  mem       REG               8,49       1583120    3407895 /lib/x86_64-linux-gnu/
lsof      26893        root  mem       REG               8,49        136936    3407917 /lib/x86_64-linux-gnu/
lsof      26893        root  mem       REG               8,49       1534592    4079033 /usr/lib/locale/locale-archive
lsof      26893        root    4r     FIFO                0,8           0t0     630778 pipe
lsof      26893        root    7w     FIFO                0,8           0t0     630779 pipe
[email protected]:/home/neo#

if you are having problems with umounting a partition or a hung process that is accessing a file, then this command will help you out. Once you find out the PID of the offending process you may then kill it with the kill -9 command to free up the file.

The ps command is also a good way to view a list of running processes. Use the ps aux command to view a complete list of all running processes. The pstree command will show a tree view of running processes. An example below, you use the pstree $LOGNAME command to view all running processes belonging to your user.

[email protected]:~/Documents$ pstree neo
















           │      └─xclock




[email protected]:~/Documents$

As you can see, the lxsession is the master process and the lxpanel, openbox and pcmanfm processes are running under that process. As with the lxterminal command, there are processes that were executed within that terminal, therefore they are under the lxterminal process.

The ps axjf command will also print out a process tree of running processes. Searching for a running process is easy, the grep command is used here.

[email protected]:~/Documents$ ps aux | grep bash
neo      25554  0.0  0.0  20556  3368 pts/0    Ss+  Apr16   0:00 /bin/bash
neo      26555  0.0  0.0  10748  1480 ?        S    10:31   0:00 bash /usr/bin/banshee --redirect-log --play-enqueued
neo      26830  0.0  0.0  20580  3512 pts/1    Ss   10:44   0:00 /bin/bash
neo      27346  0.0  0.0  20556  3380 pts/2    Ss   11:27   0:00 /bin/bash
neo      27430  0.0  0.0   7796   864 pts/2    S+   11:33   0:00 grep bash

This enables you to quickly find the PID of a certain process and kill it.

No comments have been made. Use this form to start the conversation :)

Leave a Reply