Introduction:-

when we run an any application or a program in a linux server it will create an instance is called process.
Here in this article we can see and discuss the process management commands one by one.
The basic commands are
TOP
HTOP
PS
PSTREE
PGREP
NICE
RENICE
and KILL command.

Each and every process uses server resources like memory, storage and computing resources to complete the job associated with each process.

Every time a new process is started it is assigned an identification number (ID) which is called process ID or PID in short.

As as Linux Admin or user, we will run into situations where we need to manage all these processes. That’s where the Linux operating system provides a lot of tools to manage running processes.

where we use this or run into :-

  • List the top running processes and server resource snapshot
  • To view all the running processes on Linux
  • To see resources used by each process
  • Change process priorities and resources available to processes.
  • Find specific process and change state of that process
  • Killing running or run away processes

The above is the situation or scenarios where we use the linux process management commands.

top command in linux:-

The most easiest and essential command for every Linux user is TOP. As the name indicates it displays overall view of the Linux system including TOP running processes.

Here we can see server statistics like uptime, load averages and running processes states in the first few lines.

It also shows top running processes with their process identification number(PID), process user, Priority, nice value, %CPU and %memory consumed by the process etc.

htop command in Linux:-

Htop is similar to TOP but more advanced with an interactive process viewer. It shows CPU,Memory and SWAP resources as text graphs.

Difference between htop and top:-

  • In htop we can scroll the list vertically and horizontally to see all processes and full command lines.
  • In top we are subject to a delay for each unassigned key you press (especially annoying when multi-key escape sequences are triggered by accident).
  • htop starts faster (top seems to collect data for a while before displaying anything).
  • In htop we don’t need to type the process number to kill a process, in top you do.
  • In htop we don’t need to type the process number or the priority value to renice a process, in top you do.
  • In htop we can kill multiple processes at once.
  • top is older, hence, more tested.

Command to List process ps :-

ps” command is the most basic command to see all the running processes on the system. It outputs all running processes of specific user or all users.

To see running processes of existing user:

ps

The output will be like this:

To see running processes of all users:

ps -aux

To view specific service/user running processes:

ps -ef | grep httpd

Command pstree :-

This “pstree” command will be useful if we want to see the running processes hierarchically arranged in tree format.

It’s very easy to understand parent and child processes using this command. It is used as a more visual alternative to the ps command. The root of the tree is either init or the process with the given pid.

Command nice :- to change process priorities

This nice command is used to assign particular priority, thus giving the process more or less CPU time than other processes.

Process priority values range from -20 to 19. Lower the nice value, higher the priority. The default nice value is 0.

It means -20 has highest priority over 15. In order to use higher priorities (negative nice values) administrator privileges are required.

When you use the command nice you start a new process and assign it priority (nice) value at the same time.

nice -3 top

The above command is used to starts the top command or process with nice value of -3.

command renice:-

This”renice” command is used to change priorities of already running processes.

In the above nice example we started process TOP with -3 priority. Let’s change that priority using renice.

syntax:

 renice -n -p -PID

Command:

renice -5 -p 25476

when we enter the above command the output is like this,

Command pgrep :-

In Linux each process is assigned a process ID, or PID. This is how the operating system identifies and keeps track of processes.

pgrep” is the useful command to get list of PID’s for a particular service or program.

For example: If you want to see list of all PID’s of apache web service or httpd.

pgrep httpd

If we enter the above command we will get output with PID’s of httpd service.

Command kill :-

Every process in Linux responds to signals. Signals are commands or instructions to processes to terminate or modify their behavior.

The default way to send signals to processes is through Kill command.

The very common kill command syntax are:

kill <pid>

This sends the TERM signal to the process. The TERM signal tells the process to please terminate. This allows the program to perform clean-up operations and exit smoothly.

If the program is misbehaving and does not exit when given the TERM signal, we can escalate the signal by passing the KILL signal:

kill -5 <pid>

we can send “-kill” instead of 5

killall -5 - httpd - all instances having the same process name

If we don’t know the process ID, we can use pkill command which works by using process name instead of PID’s.

pkill -5 firefox

The above command will kill firefox program by sending TERM signal.

Conclusion:

Linux process management is an essential task for each and every Linux administrator.

All the above tools allows you to manage system resources efficiently.

And all the above mentioned process management commands should work fine in all Linux OS like centos,Red hat,Ubuntu.

Categories: NEW/ADVANCED