Linux Basics : Part14 : Process Management

A process is a set of instructions loaded into memory. Every Process contains a unique process identification number also known as PID.

To list ongoing processes, you can use various commands such as “ps“, “top” and many more.

Each command has its own significance and give a variety of information about the process.

Let us see some commands and its usage to find specific details about a process.

Finding Process.

1. To list all running process along its owner and other information you can use the “ps” command.

ps” can be run standalone or with options.

#ps auxf

where:
a: Include processes from all terminals.
x: Includes processes not attached to terminals.
u: Prints the process owner information.
f : Prints process percentage.

ps command can be used with grep for executing advance search and finding specific processes if the details are known.

2. To find out processes based on predefined patterns you can use the “pgrep” command.

#pgrep -u root

The above command will show all processes run by user “root

3. If you happen to know the exact name of the process and you want to know the PID number, then you can use the command “pidof

#pidof bash

The above command will show the pid of the program bash, which you can then use to do other tasks.

Once you are familiar with process and how to find and list them, you may want to go step ahead in controlling the same, for that you can use signals.

Signals.

Signals are inter-process communication and are sent directly to the process. Some common signals and their uses are as below:

-> signal 15 or TERM: Terminate a process cleanly or gracefully.
-> signal 9 or KILL: Terminate a process immediately and forcefully.
-> signal 1 or HUP: Reread config files of a process.

Doing a quick “#man signal” shows a complete list of available signals.

Sending Signals to processes.

There are mainly 3 commonly used ways to send a signal to a process.

1. By Pid: Can be issued in the below way:

#kill [signal] [pid]

2. By Name:

#killall [signal] [command] OR killall [process name]

3. By Pattern:

#pkill [signal] [pattern]

Priority & Process Control.

Priority decides the amount of CPU that can be allocated to a process. The value that affects this behavior is called as a nice value.

The nice value ranges from “-20 to 19”. The lower the value the higher the priority.

We can alter the nice values of a process while starting the process or after the process is already started.

To set a nice value at the time of starting the process use the nice command.

#nice -n 5 [command]

To alter the nice value after the process has started use the renice command.

#renice 5 [pidofprocess]

Remember, only root can change the nice values.

You can run a process in the background at the time of starting it using the "&" symbol.

#[command] &

To temporarily halt a running process, use the “ctrl+z” keys, this will send "signal 17" and halt a running process.

To list the job numbers for the processes running in the background you can use the “jobs” command.

#jobs

To resume a process in the background, use the bg command.

#bg [% job number]

To resume a process in the foreground, use the fg command.

 #fg [% job number]

To send a signal to a specific job:

#kill [signal] [% job number]

Well that’s it for this post, see you in the next post of blog.avoidingtech.com

Leave a Comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.

error: Content is protected !!