Process Management

The basic Linux monitoring commands such as pstree and ps -auxw and top will inform you of the processes running on your system. Sometimes a process must be terminated. To terminate a process:

  1. Identify the process:
    • pstree -p
    • ps -auxw
    • top
  2. Kill the process:
    • kill <process-id-number>
    • killall <command-name>

This will perform an orderly shutdown of the process. If it hangs give a stronger signal with: kill -9 <process-id-number>. This method is not as sanitary and thus less preferred.

A signal may be given to the process. The program must be programmed to handle the given signal. See /usr/include/bits/signum.h for a full list. For example, to restart a process after updating it’s configuration file, issue the command kill -HUP <process-id-number>

In the previous example, the HUP signal was sent to the process. The software was written to trap for the signal so that it could respond to it. If the software (command) is not written to respond to a particular signal, then the sending of the signal to the process is futile.

Identify all known signals: fuser -l

Process Management GUI Tools:

  • xosview: Oldie but goodie.
  • gnome-system-monitor
  • ksysguard (comes with SuSE)
  • QPS (See below)


Also see the GUI tool QPS. (Handles MOSIX cluster) This tool is outstanding for monitoring, adjusting nice values (priorities), issue signals to the process, view files the process is using, the memory, environmnet variables and sockets the process is using. RPM available from this site. It is so simple to use, no instructions are necessary. It can monitor a program to make sure it isn’t doing something bad. It is also reverse engineer what applications are doing and the environments under which they run. I love this tool!!

Note: The RPM provided was compiled for RedHat 7.x. For RedHat 8.0+ one must install the appropriate QT library RPMs to satisfy dependencies:

   rpm -ivh qt2-2.3.1-8.i386.rpm qt2-Xt-2.3.1-8.i386.rpm qt2-devel-2.3.1-8.i386.rpm qt2-static-2.3.1-8.i386.rpm

Then install qps: rpm -ivh qps-1.9.7-5.i386.rpmNote Fedora Core 3: rpm -ivh qt2-2.3.1-8.i386.rpm qps-1.9.7-5.i386.rpm
These older RH 8.0 and 7 binary release rpms even work on my AMD64 Fedora Core 3 x86_64 OS system.

Configuring QPS to run applications against a process: Select “Command” + “Edit Commands…” + “Add…”

  • Description: GDB
    Command Line: xterm -T "GDB %C" -e gdb -d /directory-where-source-code-is-located --pid=%p
  • Description: gdb
    Command Line: xterm -T "gdb %c (%p)" -e gdb /proc/%p/exe %p &
    (As issued in RPM)
    gdb man page
  • Description: strace
    Command Line: xterm -T "strace %c (%p)" -e sh -c 'strace -f -p%p; sleep 10000'&
    (show process system calls and signals. Try it with the process qps itself.)
    Show output written by process:
    xterm -T "strace %c (%p)" -e sh -c 'strace -f -q -e trace=write -p%p; sleep 10000'&
    strace man page
  • Description: truss (Solaris command)
    Command Line: xterm -T "truss %C (%p) -e sh -c 'truss -f -p %p; sleep 1000'&

IPCs: Semaphores, Shared Memory and Queues

Note that some processes may use Linux InterProcess Communication or IPC (semaphores, shared memory or queues) which may need to be cleaned up manually:

  1. Identify the semaphores: ipcs
    ipcs -q List share queues.
    ipcs -m Shared memory.
    ipcs -s List Semaphores.
  2. Remove the semaphores: ipcrm -s <ipcs id>

Example: If you are running Apache, you may see the following:

[root@node DIR]#  ipcs -m                    

------ Shared Memory Segments --------
key       shmid     owner     perms     bytes     nattch    status
0x00000000 341504    nobody    600       46084     27        dest

lsof – Processes attached to open files or open network ports:

The command lsof shows a list of processes attached to open files or network ports.

  • List processes attached to a given file: lsof filename:
    [root@node DIR]# lsof /var/log/mailman/qrunner
    python  18538 mailman    4u   REG    3,5  657 486746 /var/log/mailman/qrunner
    python  18578 mailman    6u   REG    3,5  657 486746 /var/log/mailman/qrunner
    python  18579 mailman    6u   REG    3,5  657 486746 /var/log/mailman/qrunner
    python  18580 mailman    6u   REG    3,5  657 486746 /var/log/mailman/qrunner
    python  18581 mailman    6u   REG    3,5  657 486746 /var/log/mailman/qrunner
    python  18582 mailman    6u   REG    3,5  657 486746 /var/log/mailman/qrunner
    python  18583 mailman    6u   REG    3,5  657 486746 /var/log/mailman/qrunner
    python  18584 mailman    6u   REG    3,5  657 486746 /var/log/mailman/qrunner

    The process attached to an open file can be killed using the command fuser -ki filename

  • List all open files on system: lsof
    (Long list)
  • List all files opened by user: lsof -u user-id
  • The commands netstat -punta and socklist will list open network connections.
    Use the command lsof -i TCP:port-number to see the processes attached to the port.

    [root@node DIR]# lsof -i TCP:389
    slapd    5927 ldap    6u  IPv4 7560023       TCP *:ldap (LISTEN)
    slapd    5928 ldap    6u  IPv4 7560023       TCP *:ldap (LISTEN)
    slapd   21185 ldap    6u  IPv4 7560023       TCP *:ldap (LISTEN)
    slapd   21186 ldap    6u  IPv4 7560023       TCP *:ldap (LISTEN)
    slapd   21193 ldap    6u  IPv4 7560023       TCP *:ldap (LISTEN)

    This shows that the command slapd running under user id ldap is running five process connected to port 389.

Restricting user resources:

  • ulimit: (bash shell command)Shell and process resources may be controlled and reported using the ulimit command. Display the limits of a shell using the bash command “ulimit -a“. Limits can be set for the number of open files and processes, memory and virtual memory etc.
  • See limits assigned in /etc/security (discussed below)
  • Modify process scheduling priority: Range goes from -20 (highest priority) to 19 (lowest).
    • Lower scheduling priority (runs slower and less likely to slow you down.)
      nice -n 19 program-to-launch
      Default for “nice -n” is 10
    • Show default for any process: nice executable
      Shows nice value to be used if run.

Tinggalkan Balasan

Isikan data di bawah atau klik salah satu ikon untuk log in:


You are commenting using your account. Logout / Ubah )

Gambar Twitter

You are commenting using your Twitter account. Logout / Ubah )

Foto Facebook

You are commenting using your Facebook account. Logout / Ubah )

Foto Google+

You are commenting using your Google+ account. Logout / Ubah )

Connecting to %s

%d blogger menyukai ini: