In this tutorial, we will learn about the Linux process. As we already learned about what is Linux in our previous tutorial.
#what is process?
Process is
the instance of the current running program in the system. In other terms,
whenever any command you give to the Linux, it’s created, or starts, a new
process in execution.
For
Example:- # pwd command when issued which is used to listing the present working directory(PWD) where the user is in, a
process starts. In the below image, you can see the PWD command shows the
present working directory where the user is in. In the below image, the user is
inside the root directory.
#Process ID
Each process in the system has a unique ID which is known as the Process ID. The operating system tracks processes with the help of process ID which is unique for each process.
#How to check the PID(Process ID) for the current running process?
There are
many alternatives to get the PID (Process ID) of the current running process
like
# ps
command:- you can
see the below image of how we can get the PID (Process ID) of the current running
process.
# TOP command:- You can see
the below image, how we can get the Process ID (PID) of the current running
process.
The above two commands are recommended command to check the PID of the
Process. There are many other commands apart from the above two available which
you can find in the below tables and use to get the same as you see in the above
images.
# Alternative commands to display PID of the process:-
#
pidof |
#
pgrep |
#
ps |
#
pstree |
#
ss |
#
netstat |
#
lsof |
#
fuser |
#Types of Process
When you run a command (start a
process), there are 2 ways you can run it:-
1) Foreground Process:- when you
run any program it’s always run on the screen and it’s got the input from the
keyboard and display output on the screen. The main drawback of this command is until the current process
not stops you cannot execute the other process.
For Example:- If you want to list all the files in your
current directory, you can use the ls command. This
command list all files which are resided in the directory you want to
display.
The process which is running in the foreground is directly displayed output to my screen and if the ls command wants any input (which are not required), waits for the keyboard to five inputs to the command.
2) Background Process:- the process which doesn’t require any input from the keyboard is known as the background process. If the process wants any user input, it’s waiting. The main advantage of this process is that you can run another process without the wait for the process to stop its execution. The easiest way to start a background process is to add an ampersand (&) at the end of any command. Like # pwd &
# How to Kill (or terminate) a process?
With the use
of KILL command you can terminate the currently running process on a Linux
system. If you want to kill the process first you know the Process ID of that process
you want to kill.
As we
already discussed above how to get to know about the Process ID of any process.
0 Comments