Thursday, November 24, 2011

Linux Process Management

System Processes:

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

1.First Identify the process:

#ps -eaf | grep "programe name"
or
#pstree -p
or

#ps -auxw
or

#top

2.Kill the process:

#kill <process-id-number>
#killall <command-name>

This will perform an gracefully shutdown of the process. If it unresponsive and not killed then give a stronger signal with:
kill -9 <process-id-number>.

This method is not as good and thus less preferred.

A signal may be given to the process.

To restart a process after updating it's configuration file, issue the command kill -HUP <process-id-number>

This means 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.

How you can Identify all known signals: fuser -l or kill -l

IPCs: Semaphores, Shared Memory and Queues

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

1.How to Identify the semaphores:

ipcs -q
ipcs -m
ipcs -s

-q - it Lists Share Queues
-m - Shared Memory
-s - List Semaphores

2.Remove the semaphores:

ipcrm -s <ipcs id>
Through Lsof Process Management

lsof - Shows number of Processes attached to open files or open network ports:

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

Syntax:
lsof filename:

#lsof /var/log/mailman/qrunnerpython
- The process attached to an open file can be killed using the command fuser -ki filename
- List all open files on system: lsof
- List all files opened by user: lsof -u user-id
- The commands netstat -patnu and socklist(FreeBSD command) will list open network connections.

Use the command lsof -i TCP:port-number to see the processes attached to the port.
For Example:
# lsof -i TCP:389

No comments:

Post a Comment