A process is a dynamically executing instance of a program. Linux is a multitasking operating system. This means that many processes can be running at the same time. As well as the processes we are running, there may be other users on the system also running stuff and the OS itself will usually also be running various processes which it uses to manage everything in general. Any application that runs on a Linux system is assigned a process ID or PID. This is a numerical representation of the instance of the application on the system.
Types of Processes:-
There are generally two types of processes that run on Linux. Interactive & Non-Interactive.
Interactive processes are those processes that are invoked by a user and can interact with the user. e.g. VI is an interactive process. Interactive processes can be classified into foreground and background processes. The foreground process is the process that you are currently interacting with, and is using the terminal as its STDIN (standard input) and STDOUT (standard output). A background process is not interacting with the user and can be in one of two states – paused or running.
Non-Interactive processes are those processes that are system process or Daemon. Daemon is the term used to refer to process that are running on the computer and provide services but do not interact with the console. Most server software is implemented as a daemon. e.g Apache, Samba.
Different States of Processes:-
Running: The process is either running (it is the current process in the system) or it is ready to run (it is waiting to be assigned to one of the system's CPUs).
Waiting: The process is waiting for an event or for a resource. Its of two types, interruptible and uninterruptible.
Interruptible waiting processes can be interrupted by signals whereas uninterruptible waiting processes are waiting directly on hardware conditions and cannot be interrupted under any circumstances.
Stopped: The process has been stopped or halted, usually by receiving a signal and can be restarted by some other process. A process that is being debugged can be in a stopped state.
Zombie: The process has been terminated, but information is still there in the process table. It is what it sounds like, a dead process.
Now let's start with the process management commands in Linux,
jobs
The jobs command displays the status of jobs started in the current session. If the prompt is returned with no information, then no jobs are currently running.
By default the jobs command displays the status of all stopped jobs, all running background jobs, and all jobs whose status has changed but not been reported by the shell.
Understanding the Job Number (jobID)
There are a various ways to refer to a job in the shell. The character % introduces a job specification. The JobID can be a process ID (PID) number, or you can use one of the following symbol combinations:
%Number : Use the job number such as %1 or %2.
%String : Use the string whose name begins with suspended command such as %commandName or %ping.
%+ OR %% : Refers to the current job.
%- : Refers to the previous job.
- To list all the jobs in the current session.
[root@subrat ~]# jobs
[1] Running sar 60 > /home/subrat/sar.txt &
[2]- Running sleep 10000 &
[3]+ Running sleep 1200 &
- To list process IDs in addition to the normal information.
[root@subrat ~]# jobs -l
[1] 1363 Running sar 60 > /home/subrat/sar.txt &
[2]- 1366 Running sleep 10000 &
[3]+ 1369 Running sleep 1200 &
- To list only the process ID of the job’s process group leader.
Use: # jobs -p %job-id
[root@subrat ~]# jobs -p %3
1369
[root@subrat ~]# jobs -p %2
1366
bg
fg
ps
kill
The kill command is used to terminate a processes without having to log out or restart the system. Actually, kill command is used to send a signal to a process. By default, the message sent is the termination signal, which requests that the process exit.
Syntax:
# kill PID
OR # kill -s SignalName PID
OR # kill -SignalName PID
OR # kill -SignalNumber PID
As of now remember the Signal Name & Syntax. We have a different topic for Signal details.
- To kill a single process or a background job, use the PID or the Job Number.
[root@subrat ~]# kill 1369
OR
[root@subrat ~]# kill %3
- To kill more than one process at a time.
[root@subrat ~]# kill 1366 1363
- To kill a process forcefully, use -9 potion or call KILL signal.
[root@subrat ~]# kill -9 1363
OR
[root@subrat ~]# kill -s 9 1363
OR
[root@subrat ~]# kill -s SIGKILL 1363
OR
[root@subrat ~]# kill -s KILL 1363
OR
[root@subrat ~]# kill -SIGKILL 1363
OR
[root@subrat ~]# kill -KILL 1363
- To list all the Signals.
[root@subrat ~]# kill -l
1) SIGHUP 2) SIGINT 3) SIGQUIT 4) SIGILL 5) SIGTRAP
6) SIGABRT 7) SIGBUS 8) SIGFPE 9) SIGKILL 10) SIGUSR1
11) SIGSEGV 12) SIGUSR2 13) SIGPIPE 14) SIGALRM 15) SIGTERM
16) SIGSTKFLT 17) SIGCHLD 18) SIGCONT 19) SIGSTOP 20) SIGTSTP
21) SIGTTIN 22) SIGTTOU 23) SIGURG 24) SIGXCPU 25) SIGXFSZ
26) SIGVTALRM 27) SIGPROF 28) SIGWINCH 29) SIGIO 30) SIGPWR
31) SIGSYS 34) SIGRTMIN 35) SIGRTMIN+1 36) SIGRTMIN+2 37) SIGRTMIN+3
38) SIGRTMIN+4 39) SIGRTMIN+5 40) SIGRTMIN+6 41) SIGRTMIN+7 42) SIGRTMIN+8
43) SIGRTMIN+9 44) SIGRTMIN+10 45) SIGRTMIN+11 46) SIGRTMIN+12 47) SIGRTMIN+13
48) SIGRTMIN+14 49) SIGRTMIN+15 50) SIGRTMAX-14 51) SIGRTMAX-13 52) SIGRTMAX-12
53) SIGRTMAX-11 54) SIGRTMAX-10 55) SIGRTMAX-9 56) SIGRTMAX-8 57) SIGRTMAX-7
58) SIGRTMAX-6 59) SIGRTMAX-5 60) SIGRTMAX-4 61) SIGRTMAX-3 62) SIGRTMAX-2
63) SIGRTMAX-1 64) SIGRTMAX
- To find a Signal Name.
[root@subrat ~]# kill -l 2
INT
[root@subrat ~]# kill -l 19
STOP
[root@subrat ~]# kill -l 9
KILL
- To find a Signal Number.
[root@subrat ~]# kill -l KILL
9
[root@subrat ~]# kill -l SIGKILL
9
killall
The killall command is used to kill a process having too many instances and a number of child processes. This command takes process name as argument in-place of process number.
pwdx
time
pidof
pgrep
pstree
chroot
disown
nice
renice
Types of Processes:-
There are generally two types of processes that run on Linux. Interactive & Non-Interactive.
Interactive processes are those processes that are invoked by a user and can interact with the user. e.g. VI is an interactive process. Interactive processes can be classified into foreground and background processes. The foreground process is the process that you are currently interacting with, and is using the terminal as its STDIN (standard input) and STDOUT (standard output). A background process is not interacting with the user and can be in one of two states – paused or running.
Non-Interactive processes are those processes that are system process or Daemon. Daemon is the term used to refer to process that are running on the computer and provide services but do not interact with the console. Most server software is implemented as a daemon. e.g Apache, Samba.
Different States of Processes:-
Running: The process is either running (it is the current process in the system) or it is ready to run (it is waiting to be assigned to one of the system's CPUs).
Waiting: The process is waiting for an event or for a resource. Its of two types, interruptible and uninterruptible.
Interruptible waiting processes can be interrupted by signals whereas uninterruptible waiting processes are waiting directly on hardware conditions and cannot be interrupted under any circumstances.
Stopped: The process has been stopped or halted, usually by receiving a signal and can be restarted by some other process. A process that is being debugged can be in a stopped state.
Zombie: The process has been terminated, but information is still there in the process table. It is what it sounds like, a dead process.
Now let's start with the process management commands in Linux,
jobs
The jobs command displays the status of jobs started in the current session. If the prompt is returned with no information, then no jobs are currently running.
By default the jobs command displays the status of all stopped jobs, all running background jobs, and all jobs whose status has changed but not been reported by the shell.
Understanding the Job Number (jobID)
There are a various ways to refer to a job in the shell. The character % introduces a job specification. The JobID can be a process ID (PID) number, or you can use one of the following symbol combinations:
%Number : Use the job number such as %1 or %2.
%String : Use the string whose name begins with suspended command such as %commandName or %ping.
%+ OR %% : Refers to the current job.
%- : Refers to the previous job.
- To list all the jobs in the current session.
[root@subrat ~]# jobs
[1] Running sar 60 > /home/subrat/sar.txt &
[2]- Running sleep 10000 &
[3]+ Running sleep 1200 &
- To list process IDs in addition to the normal information.
[root@subrat ~]# jobs -l
[1] 1363 Running sar 60 > /home/subrat/sar.txt &
[2]- 1366 Running sleep 10000 &
[3]+ 1369 Running sleep 1200 &
- To list only the process ID of the job’s process group leader.
Use: # jobs -p %job-id
[root@subrat ~]# jobs -p %3
1369
[root@subrat ~]# jobs -p %2
1366
bg
fg
ps
kill
The kill command is used to terminate a processes without having to log out or restart the system. Actually, kill command is used to send a signal to a process. By default, the message sent is the termination signal, which requests that the process exit.
Syntax:
# kill PID
OR # kill -s SignalName PID
OR # kill -SignalName PID
OR # kill -SignalNumber PID
As of now remember the Signal Name & Syntax. We have a different topic for Signal details.
- To kill a single process or a background job, use the PID or the Job Number.
[root@subrat ~]# kill 1369
OR
[root@subrat ~]# kill %3
- To kill more than one process at a time.
[root@subrat ~]# kill 1366 1363
- To kill a process forcefully, use -9 potion or call KILL signal.
[root@subrat ~]# kill -9 1363
OR
[root@subrat ~]# kill -s 9 1363
OR
[root@subrat ~]# kill -s SIGKILL 1363
OR
[root@subrat ~]# kill -s KILL 1363
OR
[root@subrat ~]# kill -SIGKILL 1363
OR
[root@subrat ~]# kill -KILL 1363
- To list all the Signals.
[root@subrat ~]# kill -l
1) SIGHUP 2) SIGINT 3) SIGQUIT 4) SIGILL 5) SIGTRAP
6) SIGABRT 7) SIGBUS 8) SIGFPE 9) SIGKILL 10) SIGUSR1
11) SIGSEGV 12) SIGUSR2 13) SIGPIPE 14) SIGALRM 15) SIGTERM
16) SIGSTKFLT 17) SIGCHLD 18) SIGCONT 19) SIGSTOP 20) SIGTSTP
21) SIGTTIN 22) SIGTTOU 23) SIGURG 24) SIGXCPU 25) SIGXFSZ
26) SIGVTALRM 27) SIGPROF 28) SIGWINCH 29) SIGIO 30) SIGPWR
31) SIGSYS 34) SIGRTMIN 35) SIGRTMIN+1 36) SIGRTMIN+2 37) SIGRTMIN+3
38) SIGRTMIN+4 39) SIGRTMIN+5 40) SIGRTMIN+6 41) SIGRTMIN+7 42) SIGRTMIN+8
43) SIGRTMIN+9 44) SIGRTMIN+10 45) SIGRTMIN+11 46) SIGRTMIN+12 47) SIGRTMIN+13
48) SIGRTMIN+14 49) SIGRTMIN+15 50) SIGRTMAX-14 51) SIGRTMAX-13 52) SIGRTMAX-12
53) SIGRTMAX-11 54) SIGRTMAX-10 55) SIGRTMAX-9 56) SIGRTMAX-8 57) SIGRTMAX-7
58) SIGRTMAX-6 59) SIGRTMAX-5 60) SIGRTMAX-4 61) SIGRTMAX-3 62) SIGRTMAX-2
63) SIGRTMAX-1 64) SIGRTMAX
- To find a Signal Name.
[root@subrat ~]# kill -l 2
INT
[root@subrat ~]# kill -l 19
STOP
[root@subrat ~]# kill -l 9
KILL
- To find a Signal Number.
[root@subrat ~]# kill -l KILL
9
[root@subrat ~]# kill -l SIGKILL
9
killall
The killall command is used to kill a process having too many instances and a number of child processes. This command takes process name as argument in-place of process number.
pwdx
time
pidof
pgrep
pstree
chroot
disown
nice
renice
No comments:
Post a Comment