DronaBlog

Wednesday, November 14, 2018

Process Management in Unix System

Are you looking for an article on how does process management happen in Unix? Would you like to foreground and background processes in the Unix? Are you also would you like to know about commands related to the process management? If yes, then you reached the right place. This article provides detailed information about process management in Unix system.

Overview

The new process will be created and started whenever we issue a command in the Unix system. In order to execute a program or a command, a special environment is created. e.g. If we execute the command 'grep' or 'ls', it will start the process internally.

The process ID (aka pid) is five-digit id used by Unix operating system to track process. It is unique for each process in given executing Unix environment.
The pid values repeat because all the possible numbers are used up. However, no two processes with the same pid exist in the Unix system because it is used to track each process.

Types of processes

There are two types of processes-
  1. Foreground processes
  2. Background processes

1. Foreground Processes

The process which takes input from the keyboard and sends its output to the screen is a foreground process. 

If any foreground process is running we cannot execute any other command or start any other process as prompt will not be available until the existing process is finished.
e.g. When we execute 'ls' command output is returned to the screen. It is an example of the foreground process.

2. Background Processes

The process which runs without being connected to your keyboard is called the background process.

The background process goes in wait mode if it requires any keyboard input. We can execute other commands while the existing process is running.  In order to execute the command in background mode, add an ampersand (&) at the end of the command. 
e.g. When we execute the command 'ls * &', it runs as the background process.

Commands

a) Use below command to list currently running processes
$ps

The result of this command will be
PID       TTY      TIME        CMD
18008     ttyp3    00:00:00    abc.sh
18311     ttyp3    00:03:31    test
19789     ttyp3    00:00:00    ps

b) In some cases, -f (i.e. full) option is used to get more information
$ps -f

The result of this command will be
UID      PID  PPID C STIME    TTY   TIME CMD
abcuid   1138 3062 0 01:23:03 pts/6 0:00 abc
abcuid   2239 3602 0 02:22:54 pts/6 0:00 pqer
abcuid   3362 3157 0 03:10:53 pts/6 0:00 xyz

Here,
UID: It is the user ID that the process belongs to
PID: Process ID
PPID: Parent process ID
C: CPU utilization of process
STIME: Process start time
TTY: Terminal type
TIME: CPU time is taken by the process
CMD: The command that started this process

Child and Parent Processes

  • Two ID numbers will be assigned to each process.
  • These two ID numbers are the parent process ID (PPID) and the process ID (PID) or child id.
  • In the Unix system, each user process has a parent process and hence PPID is assigned to each user process.
  • The shell will act as a parent whenever we execute any command.
  • If we see the output of the command 'ps -f', we can notice that the process ID and the parent process ID is listed.
The video below provides more information about processes in Unix system.




No comments:

Post a Comment

Please do not enter any spam link in the comment box.

Dynatrace : An Overview

  Dynatrace, a leading provider of software intelligence, offers a powerful platform designed to monitor, analyze, and optimize the performa...