Process Final
Process Final
Process Final
# ps [options]
For each process, the ps command displays the PID, the terminal identifier (TTY), the
cumulative execution time (TIME), and the command name (CMD). For example, list the
currently running processes on the system using the ps command.
# ps
PID TTY TIME CMD
1442 pts/1 00:00:00 sudo
1448 pts/1 00:00:00 su
1449 pts/1 00:00:00 bash
1666 pts/1 00:00:00 ps
The ps command has several options that you can use to display additional process
information.
-a: Prints information about all processes most frequently requested, except
process group leaders and processes not associated with a terminal
-e: Prints information about every process currently running
-f: Generates a full listing
-l: Generates a long listing
-o format: Writes information according to the format specification given in a
format. Multiple -o options can be specified. The format specification is interpreted
as the space-character-separated concatenation of all the format option
arguments.
# ps -ef | more
Here,
$ ps aux
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
timothy 29217 0.0 0.0 11916 4560 pts/21 S+ 08:15 0:00 pine
root 29505 0.0 0.0 38196 2728 ? Ss Mar07 0:00 sshd: can [priv]
can 29529 0.0 0.0 38332 1904 ? S Mar07 0:00 sshd: can@notty
RSS is the amount of physical memory this process is using. Note that this includes any memory that's shared
with other processes (eg if other processes are loaded from same executable or libraries) so it may over-report
memory usage. VSZ is the size of the virtual memory space - do not be mislead by this as it's not all "used"
memory. It includes memory in use (RSS), memory that's swapped, but usually the majority is just additional
addressing space that hasn't actually had any real memory allocated to it - in order to use that space, more
memory would need to be given to the process.
I tried to think of an analogy. Let's say you're eating dinner so you're sharing a limited supply of food
with other people. RSS is the amount of food currently on your plate. VSZ is the size of your plate. Not
all of your plate is food and it's not relevant to how much food you've claimed.
RSS is the Resident Set Size and is used to show how much memory is allocated to that process and
is in RAM. It does not include memory that is swapped out. It does include memory from shared
libraries as long as the pages from those libraries are actually in memory. It does include all stack and
heap memory.
VSZ is the Virtual Memory Size. It includes all memory that the process can access, including memory
that is swapped out, memory that is allocated, but not used, and memory that is from shared libraries.
So if process A has a 500K binary and is linked to 2500K of shared libraries, has 200K of stack/heap
allocations of which 100K is actually in memory (rest is swapped or unused), and it has only actually
loaded 1000K of the shared libraries and 400K of its own binary then:
PROCESS FLAGS
https://www.computerhope.com/unix/ups.html
After login to server via SSH, the first process ‘BASH SHELL
TERMINAL’ is started. And then, we run various other child
processes within the ‘BASH SHELL TERMINAL’.
'R' = running
'Z' = zombie
Types of Processes:--
Foreground Processes: They run on the screen and need input from
the user. For example Office Programs
Background Processes: They run in the background and usually do
not need user input. For example Antivirus.
Running a Foreground Process
To start a foreground process, you can either run it from the dashboard, or
you can run it from the terminal.
When using the Terminal, you will have to wait, until the foreground
process runs.
Particular, data-intensive tasks take lots of processing power and may even
take hours to complete. You do not want your terminal to be held up for
such a long time.
To avoid such a situation, you can run the program and send it to the
background so that terminal remains available to you.
us: user cpu time (or) % CPU time spent in user space
sy: system cpu time (or) % CPU time spent in kernel space
ni: user nice cpu time (or) % CPU time spent on low priority
processes
id: idle cpu time (or) % CPU time spent idle
wa: io wait cpu time (or) % CPU time spent in wait (on disk)
hi: hardware irq (or) % CPU time spent servicing/handling hardware
interrupts
si: software irq (or) % CPU time spent servicing/handling software
interrupts
st: steal time - - % CPU time in involuntary wait by virtual cpu
while hypervisor is servicing another processor (or) % CPU time
stolen from a virtual machine
Press 'q' on the keyboard to move out of the process display.
Status
S 'R' = running S R
'S' = sleeping
'Z' = zombie
%CPU % of CPU time 1.7 1.0
%MEM Physical memory used 10 5.1
TIME+ Total CPU time 5:05.34 2:23.42
Comman
Command name Photoshop.exe Xorg
d
Commands Description
top –v Check the top command version
Top Display processes
Press 1 To see the number of CPU
top –u Display the processes for specific user only
username
Press shift+m Sort the process list by memory usage
Press shift+p Sort the process list by CPU
Shift +N Sort the list by process ID
Shift + T Sort by the running time
Shift +R Reverse the sorting order
Shift +A To devide process status
Press C Display the full command & path
Press I Hide the load average information from top row
Press m Hide the memory information
Press u Then type the username then see process for that
user
Press q For quit
Note :-- all press * shortcut key show output after “top” command
VIRT stands for the virtual size of a process, which is the sum of memory it is actually
using, memory it has mapped into itself (for instance the video card’s RAM for the X
server), files on disk that have been mapped into it (most notably shared libraries), and
memory shared with other processes. VIRT represents how much memory the program is
able to access at the present moment.
RES stands for the resident size, which is an accurate representation of how much actual
physical memory a process is consuming. (This also corresponds directly to the %MEM
column.) This will virtually always be less than the VIRT size, since most programs
depend on the C library.
SHR indicates how much of the VIRT size is actually sharable (memory or libraries). In the
case of libraries, it does not necessarily mean that the entire library is resident. For
example, if a program only uses a few functions in a library, the whole library is mapped
and will be counted in VIRT and SHR, but only the parts of the library file containing the
functions being used will actually be loaded in and be counted under RES.
Terminating a Process
There might be times when you need to terminate an unwanted process. A process
might have got into an endless loop, or it might have hung. You can kill or stop any
process that you own. You can use the following two commands to terminate one or
more processes:
– kill
– pkill
The kill and pkill commands send signals to processes directing them to terminate. Each
signal has a number, name, and an associated event. Below are some of the most
commonly used signals with their functionalities.
Note: However, there are processes that should not be terminated, such as
the init process. Killing such processes can result in a system crash. A superuser can
kill any process in the system.
Note: The kill command terminates only those processes that you own. The root user
can use the kill command on any process.
You need to know the PID of the process before you can terminate it. You can use either
the ps or pgrep command to locate the PID of the process. Also, you can terminate
several processes at the same time by entering multiple PIDs on a single command line.
Lets see an example of kill command. We would kill the process ‘sleep 400’ as shown
below.
or
The pkill/killall command requires you to specify the name instead of the PID of the
process. For example, use the pkill command to terminate the dtmail process.
# pkill dtmail
# pgrep -l mail
#
# kill -9 PID
or
# pkill -9 process_name
ot@localhost ~]# pkill -t pts/0 -U 0 ping
Note: Sending signal 15 does not necessarily kill a process gracefully. Only if the signal
is caught by the process, it cleans itself up in order and dies. If not, it just dies.
W command:---
NICE:----
Linux can run a lot of processes at a time, which can slow down the speed
of some high priority processes and result in poor performance. Nice
command is used for change a process priority at running process
condition.
Process priority:---
-20 ---- most favourable to the process
19 ---- least favourable to the process
PR = 20 + NI
PR = 20 + (-20 to + 19)
PR = 20 + -20 to 20 + 19
To avoid this, you can tell your machine to prioritize processes as per your
requirements.
This priority is called Niceness in Linux, and it has a value between -20 to
19. The lower the Niceness index, the higher would be a priority given to
that task.
Unprivileged users are only allowed to set a positive nice level (0 to 19).
Only root can set a negative nice level (-20 to -1).
To start a process with a niceness value other than the default value use
the following syntax
If there is some process already running on the system, then you can
'Renice' its value using syntax.
To change Niceness, you can use the 'top' command to determine the PID
(process id) and its Nice value. Later use the renice command to change
the value.
74 khugepaged
19 688 alsactl
19 1953 tracker-miner-f
19 73 ksmd
5 714 rtkit-daemon 1
DF
This utility reports the free disk space(Hard Disk) on all the file systems.
If you want the above information in a readable format, then use the
command
'df -h'
Free
This command shows the free and used memory (RAM) on the Linux
system.
Summary:
Any running program or a command given to a Linux system is called
a process
A process could run in foreground or background
The priority index of a process is called Nice in Linux. Its default
value is 0, and it can vary between 20 to -19
The lower the Niceness index, the higher would be priority given to
that task
Command Description
Bg To send a process to the background
Fg To run a stopped process in the foreground
Top Details on all Active Processes
Ps Give the status of processes running for a user
ps PID Gives the status of a particular process
Pidof Gives the Process ID (PID) of a process
kill PID Kills a process
Nice Starts a process with a given priority
Renice Changes priority of an already running process
Command Description
Df Gives free hard disk space on your system
Free Gives free RAM on your system