Process Powerplay: Unleashing the Potential of Linux with Essential Process Commands and Concepts #1

Process Powerplay: Unleashing the Potential of Linux with Essential Process Commands and Concepts #1

ยท

7 min read

Processes In Linux ๐Ÿ’ฌ

  • In Linux ๐Ÿง, Processes are the running instance of the program, or in simple words, processes are the executing tasks(threads) that are executing on our computer system.

  • To say it simply, Processes in Linux are not as same as programs or commands, and to say it fairly, Commands may trigger several processes simultaneously.

  • Processes may be dependent on each other and can also be independent of each other

  • Each process has its own unique PID(Process ID) that is assigned by the Operating System which the Operating System uses to track the processes and manage them.

  • The Process uses system resources such as CPU cycles, and Peripheral devices to function and for proper utilization of these system resources, Kernel(O.S) allocates these resources to each process.

Types Of Processes ๐ŸŒŸ

User Processes

  • As the name suggests, User processes are initialized by the user and are under the control of the user.

  • User processes are created when a user uses a terminal to run a command or to start an application.

  • User Processes can be Interactive and Non-Interactive, that is, they can take user input and provide output or can also have the ability to run in the background without direct user interaction and can also be termed as Independent of the terminal for interaction.

Interactive Processes

  • You can think of it as the Subset of User Processes.

  • All Interactive Processes are User Processes but not all User Processes are interactive processes.

  • Interactive processes are focused on taking input from the User and providing output to the User.

  • Examples - firefox, bash, top, etc.

Batch Processes

  • Batch Processes are the type of process scheduling in which multiple tasks are submitted for processing as a Batch.

  • These processes are Automatic and are scheduled from the terminal and are also detached from the terminal.

  • These Processes work based on queues and FIFO(First - in - First - Out)

  • They are often executed at the time of low system activity.

  • Uses - Can be used for system maintenance, automating repetitive tasks, etc.

Daemons

  • These are the Service Processes/Background Processes which are launched at the time of System Startup and they run all the time during the system's uptime and then they wait for the system request or the user request regarding the need of their service.

  • Examples - httpd, mysqld, ntpd, sshd

Threads

  • Threads are lightweight processes that are the unit of execution within a process that comes under the main process.

  • They share the same system resources and the same memory space as their parent process.

  • Threads are scheduled and run on an individual basis by the system.

  • A process can create an individual thread at any time.

Process Scheduling and States ๐Ÿš€

Scheduler

  • When the process requires priority, the scheduler provides it, when we want to how much time a process has been taking, the scheduler lets us know.

  • And it switches the processes on and off the CPU.

States

Running State

  • A process is said to be running if it is executing instructions on the CPU or if it's waiting for the scheduler to assign it(process) some time to finish execution.

  • All the processes in the running State reside on the Run Queue, for systems with many CPU/cores there are separate Run queues for each of them.

Sleep State

  • A process is said to be in the Sleep state when, it is waiting/demanding some input or action to be taken, before getting into work.

  • Such processes reside in Wait Queue.

Zombie State

Whenever a child process finishes its execution and terminates, and if its parent process is still active then, although the child process is completed, it remains in the systems processes list of active processes. Such a state is called the Zombie state.

Processes IDs ๐Ÿชช

  • We all know, There is always a time when many processes are running simultaneously and it becomes necessary for the OS to keep a record of each of them thus by Providing unique PIDs(Process IDs) to the processes, Operating System does this.

  • PIDs help track individual processes and help in process monitoring about the resource usage, and behavior of particular processes.

Process Termination ๐Ÿ‘พ

When you are using an application and if it stops working or becomes unresponsive then, It's better to terminate it.

For Terminating a process, The following command is used:

kill -9 <pid>

Explanation of this command -

kill will send signals to the process such as termination and ending the process.

-9 is a representation of SIGKILL and SIGKILL is a kind of special signal that is not ignored by a process and when used, It immediately ends/terminates the process.

<pid> is the Process ID.

Also, It is better to know that by using this command you can terminate your processes and not the processes of another user. To terminate the processes of another user, You need to have the sudo privilege or you should be the Root User.

If you are doing so, then be aware of the consequences such as loss of data for another user therefore you should have a solid reason for terminating other user's processes.

User IDs and Types ๐Ÿ’ญ

Real User IDs (RUIDs)

Now, You may think that If there are many users and they start multiple processes then, how does the system keep track of the processes and the owner of the process (i.e. who started this process) here comes into the picture, Real User IDs

  • RUIDs are assigned to the user by the Operating System

  • Its purpose is to identify the user who started a particular process.

Effective User IDs (EUIDs)

Whenever there is a need to know about the access rights of a user, EUIDs should be referred to.

Group IDs and Types ๐Ÿ—ฏ๏ธ

Real Group IDs (RGIDs)

With a single user being part of multiple groups, Users are organized into a group and each group has a unique ID known as the Real Group IDs (RGIDs).

Effective Group IDs (EGIDs)

To know about the access rights of the group, We refer to the Effective Group IDs (EGIDs).

Priority ๐ŸŒฑ

You may think that When we talked about different processes running simultaneously in the run queue and new processes are created, how does the CPU ensure which process to run and which one to halt?

Well, the answer to this is very simple - It's through the Priorities that a particular process can be prioritized to be executed first.

  • CPU determines the priority based on the Nice Value, think of it like this, The nicer the person and he lets other people in the queue get their tickets first and he waits longer.

  • The same is the case with assigning the priority, the nicer the process based on the nice value will wait longer and let other processes in the run queue execute first.

  • -20 nice value process will get the Highest Priority, executing first and the process with the +19 value will get the lowest priority, executing last.

Load Average ๐ŸŒŒ

For a given time, the average of a load number is called a Load Average.

Processes that it considers are:

  • Those processes that are actively running on C.P.U

  • Processes Waiting for the C.P.U to be available at the run queue

  • Processes that are Waiting for a resource to be made available to them

The load average can be viewed by running w, top, or uptime. We will explain the numbers next.

To be Continued...

This was Part 1 for the Process Powerplay in Linux, Stay Tuned! for the next blog post! we will cover more Process related concepts and Commands. Also, It can be used as a Cheatsheet as my previous Linux Command Line Blogposts.

Thanks!

Did you find this article valuable?

Support Satyam Singh by becoming a sponsor. Any amount is appreciated!

ย