CSE398:SystemAdministration
ControllingProcesses
Spring2004
Componentsofaprocess
Lifecycleofaprocess
Signals
Sendsignalsusingkillandkillall
Processstates
Influenceschedulingprioritywithniceandrenice
Monitorprocesseswithpsandtop
Runawayprocesses
CSE398:SystemAdministration
[Link]
Componentsofaprocess
Aprocessistheinstantiationofaprogram
Fromthekernel'
sperspective,aprocessis:
Spring2004
Anaddressspace(thesetofmemorypageswithcode,
libraries,anddata)
Setofdatastructures(withinthekernel)
Theprocess'
saddressspacemap
Currentstatus
Executionpriority
Resourcesused
Signalmask(whichsignalsareblocked)
Theowner
Whichinstructionsarecurrentlybeingexecuted
CSE398:SystemAdministration
[Link]
Processattributes
ProcessIDPID
ParentPIDPPID
Uniqueidentifier,wrapsaround
Whenaprocessiscloned,thereisaparentandachild
RealandeffectiveuserIDUIDandEUID
EUIDisusedtodeterminewhatpermissionstheprocesshas
AlsorecordsoriginalEUID(savedUID)
Canbereaccessedlaterinprogram(evenafterchangingEUID)
RealandeffectivegroupIDGIDandEGID
Niceness
Spring2004
TheCPUtimeavailabledependsonitsschedulingpriority
Userscanmaketheirprocesses'
nicer'
totherestofthesystem
CSE398:SystemAdministration
[Link]
Processlifecycle
Anexistingprocesscallsfork(2)
ParentistoldPIDofchild
Childistold0
Childcanuseexec(orsimilar)tostartanewprogram
Whenreadytodie,processcalls_exit(2)withexit
code
Parentmustwait(2)tocollectstatusofdeadchildren
Processbecomesazombie
Resourceusage,whykilled
Orphansareremappedtoinit
Spring2004
CSE398:SystemAdministration
[Link]
Signals
Signalsareprocesslevelinterruptrequests
Uses
Interprocesscommunication
Terminaldrivercankill,interruptorsuspend
processes(CtrlC,CtrlZ)
Canbesentbyadmin(withkill)forvarious
purposes
Canbesentbykernelwhenprocessbreaksarule
Spring2004
e.g.,divisionbyzero
CSE398:SystemAdministration
[Link]
Handlingsignals
Processcandesignateasignalhandlerfora
particularsignal
Ifnohandler,kerneltakessomedefaultaction
Whenhandlerisfinishedcatchingsignal,execution
continueswherethesignalwasreceived
Processcanrequestthatparticularsignalsbeignored,
orblocked
Ifsignalisreceivedwhileblocked,oneinstanceof
thatsignalisbuffereduntilitisunblocked
Spring2004
CSE398:SystemAdministration
[Link]
Importantsignals
# Name Description
Default
Catch? Block?Dump?
1 HUP
Hangup
Terminate
Yes
Yes
No
Reset request; clean up process on terminal (modem hangup)
*csh processes ignore HUP; bash users need nohup command
2 INT
Interrupt
Terminate
Yes
Yes
No
Control-C, can catch and clean up before quiting.
3 QUIT Quit
Terminate
Yes
Yes
Yes
Similar to TERM, but generates a core dump
9 KILL
Kill
Terminate
No
No
No
Never received by process; OS terminates process.
* BUS
Bus error
Terminate
Yes
Yes
Yes
Error signal. Typically memory alignment problem.
11 SEGV Segmentation Fault Terminate
Yes
Yes
Yes
Error signal. Typically memory access to protected space.
Spring2004
CSE398:SystemAdministration
[Link]
Moresignals
# Name Description
Default
Catch? Block?Dump?
15 TERM Software termination Terminate
Yes
Yes
No
Request to terminate execution. Process can clean up, exit.
* STOP Stop
Stop
No
No
No
OS suspends execution of process until CONT received.
* TSTP Keyboard stop
Stop
Yes
Yes
Yes
Keyboard Ctrl-Z request to stop. Catchable.
* CONT Continue after stop Ignore
Yes
No
No
Continue after STOP.
* WINCH Window changed
Ignore
Yes
Yes
No
Sent by terminal emulator when config changes (resize)
* USR1 User-defined
Terminate
Yes
Yes
No
User defined. Apache restarts gracefully.
* USR2 User-defined
Terminate
Yes
Yes
No
Spring2004
CSE398:SystemAdministration
[Link]
Sendingsignals
kill [-signal] pid
killsendsTERMsignalbydefault
kill -9 pid===kill -KILL pid
Guaranteesthattheprocesswilldie
kill -USR1 910 3044
killallremovesneedforpid
sudo killall -USR1 httpd
Spring2004
CSE398:SystemAdministration
[Link]
Processstates
Processexistinoneoffourstates
Runnablecanbeexecuted
Sleepingwaitingforsomeresources
Zombietryingtodie(parenthasn'
twaited)
Stoppedprocessissuspended(notpermittedto
run)
Spring2004
GetsnoCPUtimeuntilresourceisavailable
Likesleeping,butcan'
twakeuntilCONTreceived
CSE398:SystemAdministration
[Link]
Schedulingpriority
Nicenessishinttokernelabouthowoftento
scheduletheprocess
Linuxrangesfrom20(highpriority,notnice)to
+19(lowpriority,verynice),0isdefault
User/processcanraise,butnotlowerniceness
Rootcanlower
Examples
% nice +5 ~/bin/longtask
% renice -5 8829
% sudo renice 5 -u boggs
Spring2004
CSE398:SystemAdministration
[Link]
Monitoringprocesses:ps
/bin/psprimarytool
Shows
PID,UID,priority,controlterminal
Memoryusage,CPUtime,status
Manyvariationsofps
Spring2004
psaux(BSD,Linux)
psalf(Solaris)
CSE398:SystemAdministration
[Link]
Examplepsoutput
USER
root
root
root
root
root
root
root
root
root
root
root
root
root
rpc
rpcuser
ntp
root
root
root
root
root
root
daemon
root
Spring2004
PID %CPU %MEM
1 0.0 0.0
2 0.0 0.0
3 0.0 0.0
5 0.1 0.0
6 3.0 0.0
7 0.0 0.0
8 0.0 0.0
9 0.0 0.0
13 0.0 0.0
92 0.0 0.0
589 0.0 0.0
761 0.0 0.0
766 0.0 0.0
786 0.0 0.0
814 0.0 0.0
933 0.0 0.0
1045 0.0 0.0
1092 0.0 0.0
1097 0.1 0.0
1105 0.0 0.0
1113 0.0 0.0
1209 0.0 0.0
1383 0.0 0.0
1456 0.0 0.0
VSZ RSS TTY
1364
64 ?
0
0 ?
0
0 ?
0
0 ?
0
0 ?
0
0 ?
0
0 ?
0
0 ?
0
0 ?
0
0 ?
0
0 ?
1424 340 ?
1364 244 ?
1524 360 ?
1660 484 ?
1884 1880 ?
2140 164 ?
1796 176 ?
0
0 ?
0
0 ?
1960 608 ?
1560 288 ?
1408 200 ?
1348 116 tty2
STAT START
TIME COMMAND
S
2003
3:03 init [5]
--init
SW
2003
1:35 [keventd]
SWN
2003
0:27 [ksoftirqd_CPU0]
SW
2003 465:05 [kswapd]
SW
2003 7754:49 [kscand]
SW
2003
1:16 [bdflush]
SW
2003
4:06 [kupdated]
SW<
2003
0:00 [mdrecoveryd]
SW
2003 16:12 [kjournald]
SW
2003
0:00 [khubd]
SW
2003
0:01 [eth0]
S
2003
0:48 syslogd -m 0
S
2003
0:00 klogd -x
S
2003
0:22 portmap
S
2003
1:27 [Link]
SL
2003 11:18 ntpd -U ntp -g
S
2003
0:00 xinetd -stayalive
S
2003
0:00 [Link]
SW
2003 267:24 [nfsd]
SW
2003
0:05 [lockd]
S
2003
0:02 [Link]
S
2003
1:14 crond
S
2003
0:00 /usr/sbin/atd
S
2003
0:00 /sbin/mingetty tt
CSE398:SystemAdministration
[Link]
Monitoringprocesses:top
/usr/bin/topisoptionalinsomeOSes
ShowstopnCPUusingprocesses
Spring2004
Plusotherstats,likememoryusageand
availability,systemload
Canrenicewithintop
Automaticallyrefreshesscreenevery5seconds
Canfocusonaparticularuser
CSE398:SystemAdministration
[Link]
Sampletopoutput
10:42pm up 176 days, 1:23, 4 users, load average: 0.04, 0.02, 0.00
117 processes: 116 sleeping, 1 running, 0 zombie, 0 stopped
CPU0 states: 0.0% user, 2.2% system, 0.0% nice, 97.2% idle
CPU1 states: 0.2% user, 0.1% system, 0.0% nice, 99.2% idle
Mem: 2064828K av, 2050848K used,
13980K free,
0K shrd, 131000K buff
Swap: 2047744K av, 1116880K used, 930864K free
1744800K cached
PID
6
18460
18533
18605
1
2
3
5
7
8
9
13
92
235
589
680
761
Spring2004
USER
root
root
kiran
brian
root
root
root
root
root
root
root
root
root
root
root
root
root
PRI NI
16
0
9
0
9
0
10
0
9
0
9
0
19 19
9
0
9
0
9
0
-1 -20
9
0
9
0
9
0
9
0
9
0
9
0
SIZE RSS SHARE STAT %CPU %MEM
TIME COMMAND
0
0
0 SW
2.5 0.0 7755m kscand
1872 1828 1456 S
0.1 0.0
0:00 sshd
508 504
408 S
0.1 0.0
0:00 muddleftpd
1092 1092
848 R
0.1 0.0
0:00 top
100
68
48 S
0.0 0.0
3:03 init
0
0
0 SW
0.0 0.0
1:35 keventd
0
0
0 SWN
0.0 0.0
0:27 ksoftirqd_CPU0
0
0
0 SW
0.0 0.0 465:05 kswapd
0
0
0 SW
0.0 0.0
1:16 bdflush
0
0
0 SW
0.0 0.0
4:06 kupdated
0
0
0 SW<
0.0 0.0
0:00 mdrecoveryd
0
0
0 SW
0.0 0.0 16:12 kjournald
0
0
0 SW
0.0 0.0
0:00 khubd
0
0
0 SW
0.0 0.0
0:00 kjournald
0
0
0 SW
0.0 0.0
0:01 eth0
0
0
0 SW
0.0 0.0
0:02 eth1
384 340
300 S
0.0 0.0
0:48 syslogd
CSE398:SystemAdministration
[Link]
Runawayprocesses
Whatcanyoudoaboutprocessesusingan
unusualamountofresources(memory,CPU,
diskspace)?
Identifyresourcehogsusingtopand/orps
Contactownerandaskaboutresourceusage
SuspendusingSTOPsignal(mightbreakjob)
Spring2004
Contactowner,restartorkilllater
ReniceCPUhog
CSE398:SystemAdministration
[Link]
Creatingperiodicprocesses
Automation,asyou'
veheard,iskeyto
efficiency
Insteadofmanuallyperformingtasksdaily,
weekly,ormonthly,youcanschedulethem
cron
anacron
Includestaskslike:
Spring2004
monitoring,logrotation,backups,filedistribution
CSE398:SystemAdministration
[Link]
cron
crondaemonperformstasksatscheduledtimes
crontabfilesareexaminedbycronforschedule
/etc/crontab,/etc/cron.d/*,/var/spool/cron/*
cronwakesupeachminuteandcheckstoseeif
anythingneedstobeexecuted
cronissusceptibletochangesintime
doesn'
tcompensateforwhenmachineisdown,ortime
changes(clockadjustmentsordaylightsavingstime)thatare
sufficientlylarge(3hours,atleastforsomeimplementations)
anacronworksdaily
recordswhentasklastperformed,andwillcatchupfor
Spring2004
CSE398:SystemAdministration
[Link]
missingtime
crontabfiles
Format:
minutehourdaymonthweekday[username]command
usernamenotspecifiedin/var/spool/cron/files
(filenameisusedinstead)
Examples:
Spring2004
#runmakeat2:30eachMondaymorning
302**1(cd/home/joe4/project;make)
#removefilesin/tmpnotaccessedin3days
201***find/tmpaatime+3execrmf{}'
;'
#runsystemactivityaccountingtoolevery10minutes
*/10****root/usr/lib/sa/sa111
CSE398:SystemAdministration
[Link]
Managingcrontabs
Usecrontab -etoedit
Checksoutacopy
UsesEDITOR
Resubmitsittothe/var/spool/cron/
directory
crontab -lwilllistthecontentstostdout
/etc/[Link]/etc/[Link]
cancontrolaccesstocronfacilities
Spring2004
CSE398:SystemAdministration
[Link]
Usingcron
Distributionssetupcrontabentriestoautomatically
runscriptsin
/etc/[Link]/
/etc/[Link]/
/etc/[Link]/
/etc/[Link]/
Typicaltasks:
Spring2004
Cleaningthefilesystem(editorfiles,corefiles)usingfind
Distributingfiles(mailaliases,sendmailconfig,etc.)using
rsync,rdist,orexpect
Logrotation
CSE398:SystemAdministration
[Link]