[go: up one dir, main page]

0% found this document useful (0 votes)
39 views15 pages

CH 8

The document discusses various commands to monitor and manage Linux processes. It describes how to use the ps, top, and htop commands to view running processes. It also covers using jobs, fg, bg, stop, and kill commands to control foreground and background processes. Finally, it discusses using kill, pkill, and killall commands to terminate specific processes by PID or name.

Uploaded by

sraajsolanki
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views15 pages

CH 8

The document discusses various commands to monitor and manage Linux processes. It describes how to use the ps, top, and htop commands to view running processes. It also covers using jobs, fg, bg, stop, and kill commands to control foreground and background processes. Finally, it discusses using kill, pkill, and killall commands to terminate specific processes by PID or name.

Uploaded by

sraajsolanki
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 15

Linux: CHAPTER 8

MONITORING AND MANAGING LINUX PROCESS


How to List Running Processes in Linux?
Commands:
 Ps
 Top
 Htop
The ps (process statuses) command produces a
snapshot of all running processes. Therefore,
unlike the Windows task manager, the results are
static.

a option outputs all running processes of all users in the


system.

u option provides additional information like memory and CPU


usage percentage, the process state code, and the owner of the
processes.

x option lists all processes not executed from the terminal. A


perfect example of this are daemons, which are system-related
processes that run in the background when the system is booted
up.
Linux: CHAPTER 8

ps -u [username] 

lists all running processes of a certain user.

------------------------------------------------
ps -T
prints active processes that are executed from the terminal.
Linux: CHAPTER 8

Ps aux
You can use ps aux to get more in-depth information
about your running processes.

Ps lax
You can use ps lax to get more technical details but
may display faster by avoiding user name lookups.

----------------------------------------------------------------
Linux: CHAPTER 8

Using the “top” Command


The top command is used to discover resource-hungry
processes. This Linux command will sort the list by CPU
usage, so the process which consumes the most resources
will be placed at the top.

-------------------------------------------------------
Top –u username
Use top command with ‘u‘ option will display specific
User process details.
Linux: CHAPTER 8

CONTROLLING JOBS
What are jobs ?
In Linux or Unix, a job is defined as a task or command
that has started running but not yet finished what it
is doing.
As Linux and Unix are multitasking operating systems,
they allow you to run multiple commands simultaneously.
Each running command is called a job, and is assigned a
unique id called the job number.
It is very easy to manage jobs in Linux.
The main commands you use for job control in Linux are:

 jobs - List all the jobs that are running or


suspended.
 fg - Bring the job to the foreground.
 bg - Send the job to the background.
 stop or Ctrl + z - Suspend the job.
 kill or Ctrl + c - Terminate the job.

Managing jobs in Linux


Let’s simultaneously run a few commands that
takes some time to complete.
Here we have executed 4 sleep commands and all
are started in the background as denoted by &.
Linux: CHAPTER 8

List the running jobs:

In the output above, the number within [ and ]


is the job number (job ID). The job number is
unique for each job.
Bring a job to the foreground:

Suspend the job: To suspend a job, you first bring the


job to the foreground and then press the keys ctrl+c.
Linux: CHAPTER 8

Send a job to the background:


To send a foreground process to the background,
first press the keyboard generated supend
request (ctrl+Z) in the terminal.

Terminate a job:
 Ctrl+C (To terminate a forground process).
 Kill
Linux: CHAPTER 8

KILLING PROCESS:
“Killing” a process just means “forcing the
process to quit.” This may be necessary if the
process is refusing to respond.
Commands:
 kill
 pkill
 killall
Linux provides the kill, pkill, and killall
commands to allow you to do just that. These
commands can be used with any type of process,
graphical or command line, foreground or
background.
1- Kill command
Linux: CHAPTER 8

Examples:
ps aux | grep job

------------------------------------------------
kill 22978
Output: This command will terminate the job as
well as its process.
Linux: CHAPTER 8

kill –SIGINT 8658


OUTPUT: Keyboard interrupt (ctrl+c). but job is
running in background.

kill –SIGHUP 8658


OUTPUT: Hangup the process and report to
terminate.

PROCESS CONTROL USING SIGNALS:


Each signal has a default action-
Term- Cause a program to terminate (exit) at once.
Core- Cause a program to save a memory image(core dump), then
terminate.
Stop- Cause a program to stop executing (suspend) and wait to
continue (resume).

kill -9 23027 or kill –SIGKILL 23027


Output: This command will terminate the job as
well as its process.
Linux: CHAPTER 8

------------------------------------------------
kill –SEGTERM 23070
Output: This command will terminate the job as
well as its process.
Linux: CHAPTER 8

killall control
Output: This command will terminate the job as
well as its process at once.

------------------------------------------------
kill -19 2834 or kill –SIGSTOP 2834
Output: This command will stopped the job but it
will remain in process.
Linux: CHAPTER 8

2- Pkill command
The pkill command allows you to kill a
process—or processes—by name. You do not
need to identify the process by PID.

pkill controll:
Use pkill to send a signal to one or more
processes which match selection criteria.

pkill –U username
Linux: CHAPTER 8

LOGGING USERS OUT ADMINISTRATIVELY


To log off a user, first identify the login session
to be terminated. Use the w command to list user
logins and current running processes. Note the TTY
and FROM columns to determine the session to close.
[pamasol@workstation ~]$ w

Note: To terminate all process for one user,use the


pkill command. Firstly identify the PID numbers to be
killed using pgrep.
[pamasol@workstation ~]$ pgrep –l –u username

[root@workstation ~]# pkill –SIGKILL –u username


To verify:
[root@workstation ~]# pgrep –l –u username
Linux: CHAPTER 8

User’s session killing with session id


-----------------------------------------
[roo@workstation ~] w –h –u username
[roo@workstation ~] pkill –t tty2

pstree command:
Use the pstree command to view a process
tree for the system or a single user. Use
the parent process’s PID to kill all
children they have created.
[root@host ~]# pstree –p username
[root@host ~]# pkill –p 8391
[root@host ~]# pgrep –l –u username

You might also like