Introducing process basics

Introducing process basics
A running instance of a program is called as process. A program stored in the hard disk or pen drive is not a process. When that stored program starts executing, then we say that process has been created and is running. Let’s very briefly understand the Linux operating system boot-up sequence:

1. In PCs, initially the BIOS chip initializes system hardware, such as PCI bus, display device drivers, and so on.
2.Then the BIOS executes the boot loader program.
3.The boot loader program then copies kernel in memory, and after basic checks, it calls a kernel function called start_kenel() .
4.The kernel then initiates the OS and creates the first process called init .
5.You can check the presence of this process with the following command:
   $ ps –ef
6.Every process in the OS has one numerical identification associated with it. It is called a process ID. The process ID of the init process is 1. This process is the parent process of all user space processes.
7.In the OS, every new process is created by a system call called fork() .
8.Therefore, every process has a process ID as well as the parent process ID.
9.We can see the complete process tree using the following command:
    $ pstree
You can see the very first process as init as well as all other processes with a complete parent and child relation between them. If we use the $ps –ef command,
then we can see that the init process is owned by root and its parent process ID is 0.

https://rafishaikblog.wordpress.com/introduction-to-linux-and-os-installations/

mohammedrafi@NOC-RAFI:~$ ps -ef |head -n2
UID PID PPID C STIME TTY TIME CMD
root 1 0 0 Jul04 ? 00:00:01 /sbin/init

mohammedrafi@NOC-RAFI:~$ pstree
init─┬─ModemManager───2*[{ModemManager}]
├─NetworkManager─┬─2*[dhclient]
│ ├─dnsmasq
│ └─3*[{NetworkManager}]

The following are the different types of processes:

Orphan process: If by some chance the parent process is terminated, thenthe child process becomes an orphan process. The process which created
the parent process, such as the grandparent process, becomes the parent of orphan child process. In the last resort, the init process becomes the parent of the orphan process.

Zombie process: Every process has one data structure called the processcontrol table. This is maintained in the operating system. This table contains the information about all the child processes created by the parent process. If by chance the parent process is sleeping or is suspended due to some reason and the child process is terminated, then the parent process cannot receive the information about the child process termination. In such cases, the child process that has been terminated is called the zombie process. When the parent process awakes, it will receive a signal regarding the child process termination and the process control block data structure will be updated. The child process termination is then completed.

Daemon process: Until now, we had started every new process in a Bash terminal. Therefore, if we print any text with the $ echo “Hello” command, it will be printed in the terminal itself. There are certain processes that are not associated with any terminal. Such processes are called a daemon process. These processes are running in background. An advantage of the daemon process is they are immune to the changes happening to Bash shell, which has created it. When we want to run certain background processes, such as DHCP server and so on, then the daemon processes are very useful.

To list the process associated with our current Bash shell terminal.
mohammedrafi@NOC-RAFI:~$ ps
PID TTY TIME CMD
11878 pts/2 00:00:00 ps
28532 pts/2 00:00:00 bash

To list processes along with the parent process ID associated with the current terminal.
mohammedrafi@NOC-RAFI:~$ ps -f
UID PID PPID C STIME TTY TIME CMD
mohamme+ 11879 28532 0 16:04 pts/2 00:00:00 ps -f
mohamme+ 28532 28522 0 09:48 pts/2 00:00:00 bash

To list processes with the parent process ID along with the process state.
mohammedrafi@NOC-RAFI:~$ ps -fl
F S UID PID PPID C PRI NI ADDR SZ WCHAN STIME TTY TIME CMD
4 R mohamme+ 11880 28532 0 80 0 – 5663 – 16:04 pts/2 00:00:00 ps -fl
0 S mohamme+ 28532 28522 0 80 0 – 7001 wait 09:48 pts/2 00:00:00 bash

In the preceding output, the column with S (state) shows the current state of a process, such as R for running and S for suspended state.

To list all the processes running in the operating system including system processes.

mohammedrafi@NOC-RAFI:~$ ps -ef
UID PID PPID C STIME TTY TIME CMD
root 1 0 0 Jul04 ? 00:00:01 /sbin/init
root 2 0 0 Jul04 ? 00:00:00 [kthreadd]
root 3 2 0 Jul04 ? 00:00:00 [ksoftirqd/0]
root 5 2 0 Jul04 ? 00:00:00 [kworker/0:0H]

The process names in [] are kernel threads.

mohammedrafi@NOC-RAFI:~$ ps -ef |grep sleep
mohamme+ 12245 12230 0 16:22 pts/11 00:00:00 grep –color=auto sleep

mohammedrafi@NOC-RAFI:~$ sleep 1000

mohammedrafi@NOC-RAFI:~$ ps -ef |grep sleep
mohamme+ 12246 28532 0 16:22 pts/2 00:00:00 sleep 1000
mohamme+ 12248 12230 0 16:22 pts/11 00:00:00 grep –color=auto sleep

mohammedrafi@NOC-RAFI:~$ sleep 1000 &
[1] 12264

mohammedrafi@NOC-RAFI:~$ jobs
[1]+ Running sleep 1000 &
mohammedrafi@NOC-RAFI:~$ sleep 2000 &
[2] 12297
mohammedrafi@NOC-RAFI:~$ sleep 500 &
[3] 12300
mohammedrafi@NOC-RAFI:~$ jobs
[1] Running sleep 1000 &
[2]- Running sleep 2000 &
[3]+ Running sleep 500 &

mohammedrafi@NOC-RAFI:~$ fg 1
sleep 1000
^C

mohammedrafi@NOC-RAFI:~$ fg 3
sleep 500
^Z
[3]+ Stopped sleep 500
mohammedrafi@NOC-RAFI:~$ jobs
[2]- Running sleep 2000 &
[3]+ Stopped sleep 500

mohammedrafi@NOC-RAFI:~$ jobs -l
[2]- 12297 Running sleep 2000 &
[3]+ 12300 Stopped sleep 500

you can press the Ctrl + C key combination to terminate the process.
If we want to make the process to stop executing and get it suspended, then press Ctrl + Z.

mohammedrafi@NOC-RAFI:~$ ps -eo comm,pcpu,pmem –sort -pcpu | head
COMMAND %CPU %MEM
chrome 25.2 8.4
chrome 14.0 3.7
chrome 3.5 4.9
chrome 2.9 7.5
chrome 1.7 6.0
chrome 1.7 5.9
Xorg 1.6 1.3
chrome 1.6 6.5
compiz 1.5 1.5

########################################################

https://rafishaikblog.wordpress.com/2016/04/29/vmstatiostatmpstat/

The iostat command generates three types of reports: the CPU Utilization report, the Device Utilization report and the Network Filesystem report.

CPU Utilization Report

The first report generated by the iostat command is the CPU Utilization Report. For multiprocessor systems, the CPU values are global averages among all processors. The report has the following format:

%user Show the percentage of CPU utilization that occurred while executing at the user (application) level.
%nice Show the percentage of CPU utilization that occurred while executing at the user level with nicepriority.
%system Show the percentage of CPU utilization that occurred while executing at the system (kernel) level.
%iowait Show the percentage of time that the CPU or CPUs were idle during which the system had an outstanding disk I/O request.
%steal Show the percentage of time spent in involuntary wait by the virtual CPU or CPUs while the hypervisor was servicing another virtual processor.
%idle Show the percentage of time that the CPU or CPUs were idle and the system did not have an outstanding disk I/O request.

Device Utilization Report

The second report generated by the iostat command is the Device Utilization Report. The device report provides statistics on a per-physical device or partition basis. Block devices and partitions for which statistics are to be displayed may be entered on the command line. If no device nor partition is entered, then statistics are displayed for every device used by the system, providing that the kernel maintains statistics for it.

If the ALL keyword is given on the command line, then statistics are displayed for every device defined by the system, including those that have never been used. Transfer rates are shown in 1K blocks by default, unless the environment variable POSIXLY_CORRECT is set, in which case 512-byte blocks are used. The report may show the following fields, depending on the flags used:

Device This column gives the device (or partition) name as listed in the /dev directory.
tps Indicate the number of transfers per second that were issued to the device. A transfer is an I/O request to the device. Multiple logical requests can be combined into a single I/O request to the device. A transfer is of indeterminate size.
Blk_read/s (kB_read/s, MB_read/s) Indicate the amount of data read from the device expressed in a number of blocks (kilobytes, megabytes) per second. Blocks are equivalent to sectors and therefore have a size of 512 bytes.
Blk_wrtn/s (kB_wrtn/s, MB_wrtn/s) Indicate the amount of data written to the device expressed in a number of blocks (kilobytes, megabytes) per second.
Blk_read (kB_read, MB_read) The total number of blocks (kilobytes, megabytes) read.
Blk_wrtn (kB_wrtn, MB_wrtn) The total number of blocks (kilobytes, megabytes) written.
rrqm/s The number of read requests merged per second that were queued to the device.
wrqm/s The number of write requests merged per second that were queued to the device.
r/s The number (after merges) of read requests completed per second for the device.
w/s The number (after merges) of write requests completed per second for the device.
rsec/s (rkB/s, rMB/s) The number of sectors (kilobytes, megabytes) read from the device per second.
wsec/s (wkB/s, wMB/s) The number of sectors (kilobytes, megabytes) written to the device per second.
avgrq-sz The average size (in sectors) of the requests that were issued to the device.
avgqu-sz The average queue length of the requests that were issued to the device.
await The average time (in milliseconds) for I/O requests issued to the device to be served. This includes the time spent by the requests in queue and the time spent servicing them.
r_await The average time (in milliseconds) for read requests issued to the device to be served. This includes the time spent by the requests in queue and the time spent servicing them.
w_await The average time (in milliseconds) for write requests issued to the device to be served. This includes the time spent by the requests in queue and the time spent servicing them.
svctm The average service time (in milliseconds) for I/O requests that were issued to the device. Warning! Do not trust this field anymore! This field will be removed in a future sysstat version.
%util Percentage of CPU time during which I/O requests were issued to the device (bandwidth utilization for the device). Device saturation occurs when this value is close to 100%.

mohammedrafi@NOC-RAFI:~$ nfsiostat

 

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s