Process Management Commands in Linux:
‘ps‘ is one of the basic commands in Linux to view the processes on the system. It lists the running processes in a system along with other details such as process id, command, cpu usage, memory usage etc. Some of the following options come handy to get more useful information
ps -a - List all the running / active processes
ps -ef |grep - List only the required process
ps -aux - Displays processes including those with no terminals(x) Output is user oriented (u) with fields like USER, PID, %CPU, %MEM etc
pstree – In Linux, every process gets spawned by its parent process. This command helps visualize the processes by displaying a tree diagram of the processes showing the relationship between them. If a pid is mentioned, the root of the tree will be the pid. Else it will be rooted at init.
nice – With the help of nice command, users can set or change the priorities of processes in Linux. Higher the priority of a process, more is the CPU time allocated by the kernel for it. By default, a process gets launched with priority 0. Process priority can be viewed using the top command output under the NI (nice value) column.
Values of process priority range from -20 to 19. Lower the nice value, higher the priority.
nice --3 top
renice – It is similar to nice command. Use this command to change the priority of an already running process. Please note that users can change the priority of only the processes that they own.
enice -n -p - change the priority of the given process
ulimit – Command useful in controlling the system-wide resources available to the shells and processes. Mostly useful for system administrators to manage systems that are heavily used and have performance problems. Limiting the resources ensures that important processes continue to run while other processes do not consume more resources.
ulimit -a – Displays the current limits associated with the current user.
fg , bg – Sometimes, the commands that we execute take a long time to complete. In such situations, we can push the jobs to be executed in the background using ‘bg’ command and can be brought to the foreground with the ‘fg’ command.
We can start a program in background by using the ‘&’ :
find . -name *iso > /tmp/res.txt &
A program that is already running can also be sent to the background using ‘CTRL+Z’ and ‘bg’ command:
find . -name *iso > /tmp/res.txt &
this starts the job in the background. ctrl+z – suspend the currently executing foreground job
bg – push the command execution to background
We can list all the background processes using ‘jobs’ command jobs
We can bring back a background process to foreground using the ‘fg’ command. fg %