Processes & Daemons

17
Processes & Daemons Chapter IV / Part III

description

Processes & Daemons. Chapter IV / Part III. Commands. Internal commands: alias, cd, echo, pwd, time External commands, code is in a file: grep, ls, more Command (usually) is a file Binary or shell script ls is actually /bin/ls command files set to executable - PowerPoint PPT Presentation

Transcript of Processes & Daemons

Page 1: Processes & Daemons

Processes & DaemonsChapter IV / Part III

Page 2: Processes & Daemons

Commands

• Internal commands: alias, cd, echo, pwd, time

• External commands, code is in a file: grep, ls, more

• Command (usually) is a file• Binary or shell script

• ls is actually /bin/ls

• command files set to executable

• Can use relative pathname if in PATH

• echo $PATH

• add to path• export PATH=$PATH:~/bin

Page 3: Processes & Daemons

Processes

• Processes lie at the heart of all Unix/Linux OS• Very crucial to understanding the operating system

• Process - an independently running program• has own set of resources, such as CPU time, memory, hard disk

space

• Linux is a multiprocessing OS• multiple processes running at the same time

• Process scheduler: part of kernel

• processes can communicate

Page 4: Processes & Daemons

Processes

• Resources managed by kernel• everything else is a process

• shell processes & daemons

• forking

• ps

• top

Page 5: Processes & Daemons

/proc

• Useful for analyzing processes and hardware

• Numbered directory for running process

• Example• cmdline : the parent command line

• status : current status

• cwd : current working directory

• Hardware info • meminfo

• ioports

Page 6: Processes & Daemons

Forking Example

Page 7: Processes & Daemons

Process states

Linux Processes state diagrams

Page 8: Processes & Daemons

Background Processes

• started with an ‘&’

• jobs

• fg• bring into foreground

• bg• resumes execution

• pgrep -f <process-name>

• Sequential process execution• cmd1; cmd2; cmd3

• Parallel execution• cmd1& cmd2 & cmd3

Page 9: Processes & Daemons

Process creation

• By forking

• what happens when command wc input.txt is executed• shell searches for wc and input.txt

• checks wc for permission

• calls fork to create a child shell

• child shell calls exec to become wc

• wc executes

• control is returned to shell

Page 10: Processes & Daemons

Process hierarchy

• System starts with GRUB• starts kernel

• init - PID 1 (started by swapper (PID 0))

• initialized background daemons

• initializes and mounts root filesystem

• starts getty on every terminal for login process

• login

• success: forks a shell• shell continues till <Ctrl-D>

• failure: goes back to getty

Page 11: Processes & Daemons

Boot process

Page 12: Processes & Daemons

Process hierarchy

Page 13: Processes & Daemons

Processes

• only init and swapper are permanent

• ps -e f or pstree • shows hierarchical view of processes

• pstree is more compact view

• ulimit

Page 14: Processes & Daemons

Daemons

• Background system processes• monitor hardware

• networking tasks

• schedule tasks

• usually end with a d• lpd, ftpd, httpd, sshd, ....

• directly owned by init process

• usually launched at boot time

Page 15: Processes & Daemons

Runlevels

• Runlevel: current system state• 0 : system at halt

• 6: reboot

• 1: single user mode

• 2 - 5: different stages of system execution

• runlevel; who -r

• init manages the runlevel

• /etc/inittab• lists which processes are started when

Page 16: Processes & Daemons

inittab• /etc/inittab format

• id:runlevel:action:process

• specifying default level• id:3:initdefault:

Page 17: Processes & Daemons

rc.d directories

• Under /etc/• each corresponds to a runlevel

• Hold scripts (programs) for startup and kill• links to /etc/init.d

• S* - starting

• K* - killing

• explicitly start or stop a service