Get Even More Visitors To Your Blog, Upgrade To A Business Listing >>

Linux processes

A process is a running program within the Operating System. A process will contain code that can be interpreted by the system processor. Because Linux and Windows use different executable structures, a program that runs on one OS cannot run on the another. A file that’s stored on the hard drive must be first loaded into RAM to be able to execute its instructions. The kernel is responsible for managing system resources and it gives control over CPU to different Processes loaded into RAM. We’ve discussed previously about Linux boot process so please check out that article before proceeding further. In our days Operating Systems are multi-tasking which offers the possibility of running multiple programs at the same time. The kernel maintains a process table in which it stores information for each process such as:

  • PID or process ID – it’s a number from 0 to 65535 that uniquely identifies a process .
  • memory space –  the kernel is responsible for dividing RAM memory for each process so they do not interfere with each other.
  • UID, GID – group and user IDs determine the permissions with which a process is executed.
  • the parent process
  • the terminal on which the process is connected.
A process can spawn other processes within the System, this is called the parent process and spawned processes are also known as subprocesses or child processes. If you don’t know by now, in Linux, the init process is the first process executed when the OS is booted. init will always have the PID equal to 0 and all processes are spawned under it. When a process finishes its execution, all resources that were allocated are returned to the resource pool and in the process table the exit code of the process is loaded. If a process has successfully finished its operation, the process table will stored the value 0. When the parent process reads and acknowledges the status code, the subprocess entry is deleted from the table.

When the parent process terminates before the child process finishes its execution, the subprocess becomes an orphan process and its the registered under init which terminates its execution.
A process can have one of the following STATE:
Running – the process is running or it waits to receive access on the CPU
Waiting – the process is waiting for an event to occur or it waits for certain resources. There are two types of waiting processes:

  1. interruptible – may be interrupted by signals
  2. uninterruptible – cannot be interrupted and are dependent to hardware conditions

Stopped – the process has been stopped
Zombie – a process that’s stuck between finishing its execution and the moment it’s deleted from the process table.

Commands used to interact with System processes:

Use the ps -el command to view the current running processes:

View Linux running processes

PID – process ID
S – State
PPID – Parent process ID
TIME – how long the process has used the CPU
COMMAND – command executed by the process
There are multiple options that can be used with ps command. Check its man page or use the help paramter to view the available options. I also use ps -aux command often

 ps command supports a lot of parameters that can help you a when trying to get processes information on a Linux Operating System. I personally prefer using the -faux parameters because it will display a tree like structure with full process information:

ps -faux

Linux process information

Another useful command that can be used to gather Linux process information is the top command. You can use top to view running processes, kill a specific process, view resources used by each process, sort processes by a specific criteria (CPU, Memory, PID, etc.) and many others. I think top is one of the best commands that you can use to view the overall System usage and it’s available by default in most Linux distributions.

gather Linux process information

htop and atop are two enhanced versions of top command. They are not available by default on most distributions but, you can easily install them by using the following command: yum install atop htop. I like htop a lot because it offers an interactive interface that can easily be used to manipulate processes:

htop command 

lsof or list of open files is a command that’s useful when you want to view the files opened by a certain process. lsof can be used with the -p parameter to specify a certain PID to get opened files for a specific process:

List opened files in Linux

tree and pstree are used to view a structured tree of all the processes running on the OS. I prefer using the pstree with the -Ap option:
pstree -Ap

pstree command in Linux

If you are using Linux OS on a daily basis then you are probably familiar with most of the information presented in this article. I’ve written it for those that are just beginning their Linux journey and want to learn new stuff about it. Processes play an important role within an OS so knowing how to interact with them is a must have skill. There may be other information that needs mentioned here so please post a comment if you have anything to add. Wish you all the best and stay tuned for the following articles.




This post first appeared on ITtrainingday | It's All About IT And Much More…, please read the originial post: here

Share the post

Linux processes

×

Subscribe to Ittrainingday | It's All About It And Much More…

Get updates delivered right to your inbox!

Thank you for your subscription

×