Transcript runlevel
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
Can use relative pathname if in PATH
echo $PATH
add to path
•
export PATH=$PATH:~/bin
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
Processes
• Resources managed by kernel
• everything else is a process
• shell processes & daemons
• forking
• ps
• top
/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
Forking Example
Process states
Linux Processes state diagrams
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
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
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
Boot process
Process hierarchy
Processes
•
•
•
only init and swapper are permanent
ps -e f or pstree
•
•
shows hierarchical view of processes
pstree is more compact view
ulimit
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
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
inittab
• /etc/inittab format
• id:runlevel:action:process
• specifying default level
•
id:3:initdefault:
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