process management in linux

18
Process Management in Linux Manikandan.C 9677718889 Senior Redhat Trainer

Upload: mazenetsolution

Post on 14-Apr-2017

286 views

Category:

Education


0 download

TRANSCRIPT

Page 1: Process management in linux

Process Management in Linux

Manikandan.C9677718889

Senior Redhat Trainer

Page 2: Process management in linux

!!!Process!!! what it is ??

• A program is a series of instructions that tell the computer what to do.

• When we run a program, those instructions are copied into memory and space is allocated for variables and other stuff required to manage its execution.

• This running instance of a program is called a process and it's processes which we manage.

Page 3: Process management in linux

For Example

create a file called user under /bin.

# vim /bin/user

useradd king

:wq# chmod a+x /bin/user

Giving a command user an user named king will be created as a result.

# user

Page 4: Process management in linux

1st -> As soon as we open a terminal a process name bash is started. . Rite ???? Tis systemd the parent process for all descendant process is responsible.

2nd -> users are creating process by command to execute some program that is process.

Who is that creating

process ??

Systemd, most of

the daemon process

are created ,handled

and controlled

Users, all the commands in the foreground creates process

Page 5: Process management in linux

Description of process

• Like humans even process has the information like when it is created,

• address space of allocated memory,• security properties including ownership credentials

and privileges, • one or more execution threads of program code, and

the process state.

NOTE: All processes are descendants of the first system process SYSTEMD.

Page 6: Process management in linux

Small briefing on -> fork, pthreads.

FORK:Fork is nothing but an existing parent process

duplicates its own address space and create a new child process structure.

Pthreads:(POSIX THREADS)Parallel execution model which allows a program

to control multiple different flows of work that overlap in time.

Mainly for the multitasking purpose

Page 7: Process management in linux

Linux Process states

A process (which includes a thread) on a Linux machine can be in any of the following states –

RUNNING

SLEEPING

STOPPED

ZOMBIE

Page 8: Process management in linux

Types of terminal

• Tty and pty: tty is called teletype where user interacts

with the system. Pty is called as the psuedoterminal where the

process uses as its terminal in the background. And many would have came across the pts terminal where pts is nothing but the slave part of pty terminal.

Page 9: Process management in linux

RUNNING• When a command triggers a program, the process

is automatically

Name Flag Kernel-defined state and description

Running R TASK_RUNNING - The process is either executing on a CPU or waiting to be executed.

Page 10: Process management in linux

Sleeping

Sleeping

STASK_INTERRUPTIBE: The process is waiting for some condition: a h/w request , system resource access or signal. When an event or signal satisfies the condition, the process returns to Running.

D TASK_UNINTERRUPTIBLE - Like TASK_INTERRUPTIBLE, except that delivering a signal to the sleeping process leaves its state unchanged.

K TASK_KILLABLE: identical to D state, but modifies to allow the waiting task to respond to a signal to be killed.

Page 11: Process management in linux

STOPPEDName Flag Description

Stopped

T TASK_STOPPED: The process has been stopped, usually by being signaled by a user or another process . The process can be continued (resumed) by another signal to return to Running.

T TASK_TRACED: A process that is being debugged is also temporarily Stopped and shares the same T flag.

Page 12: Process management in linux

ZOMBIE

Name Flag Description

Zombie

Z EXIT_ZOMBIE - Process execution is terminated, but the parent process has not yet issued a wait4( ) or waitpid( ) system call. The OS will not clear zombie processes until the parent issues a wait()-like call

X EXIT_DEAD: when the parent cleans up (reaps) the remaining child process structure, the process is now released completely. This state will never be observed in process-listing utilities.

Page 13: Process management in linux

Process

Process monitoring(top,sar,watch)

Managing process (ps)

Killing process(kill, pkill)

Setting priority(nice,renice)

Page 14: Process management in linux

Process commands usage

Ps • Ps -ax• Ps –aux• Ps –lax• Pstreetop

• Monitoring cpu memory and process utilization

• Kill user and system process

Kill Prioritie

s: Nice ,renice >

Page 15: Process management in linux

Examples

> To display all the process: # ps –ef # ps ax

> To display process by user:# ps –f -u apache,postfix # ps –f -u linuxguy

Page 16: Process management in linux

> To show process by name or process Id:#Ps -C apache2# ps -f -p 2764

> To get the information on particular process: # ps –ef | grep postfix

Page 17: Process management in linux

> To display threads of process: # ps -p 2764 –L

> To know the parent id of the process:# ps –ppid 2543

> To customize the view of process display:Ps –eo pid,uname,pcpu,pmem,comm

> To list process in hierarchy:# ps –ef - - forest

Page 18: Process management in linux

Thanks for watching