Professional Documents
Culture Documents
Controlling Processes & Periodic Processes: Weesan Lee
Controlling Processes & Periodic Processes: Weesan Lee
Roadmap
What is a process? What is a setuid process? How to create a process? Signals How to send signals to the processes? Process States Niceness Monitor Processes Periodic Processes Q&A
What is a process?
PID PPID UID & EUID (used for access permission) GID & EGID (used for access permission) Status Niceness or nice value
A regular process
A setuid process
-rwsr-xr-x 1 root root 57908 Nov 30 14:35 /bin/mount -rwsr-xr-x 1 root root 35864 Mar 14 2007 /bin/ping -rwsr-xr-x 1 root root 31244 Mar 14 2007 /bin/ping6 -rwsr-xr-x 1 root root 24060 Mar 21 2007 /bin/su -rwsr-xr-x 1 root root 38840 Nov 30 14:35 /bin/umount
$ emacs
// Bash switch (fork()) { case -1: // Error break; case 0: // Child execv("emacs", ...); break; default: // Parent wait(); break; } // Bash clone switch (fork()) { case -1: // Error break; case 0: // Child execv("emacs", ); break; default: // Parent wait(); break; }
Signals
Signals (cont)
3 QUIT
Ctrl-Z
weesan 857 0.0 0.0 13312 7952 pts/5 S Apr15 0:05 emacs
$ kill -9 857
$ killall -9 emacs
Process States
Runnable (R)
Ready to be executed
Get no CPU time until receiving a signal Exited process whose status hasnt been collected Display as <defunct> on ps, Process stopped by STOP or TSTP signal
Sleeping (S)
Zombie (Z)
Stopped (T)
Niceness
-20 to +19 A high nice value means a low priority Inherited from the parent Can increase but not decrease
For example:
Monitor Processes
ps
$ ps auxw | less $ ps laxw | less $ ps auxw | awk -F' ' '{ print $1, $2, $10; }'
top
strace
Show every system call and signal a process receives $ strace -p pid List open files $ lsof -u userid $ lsof -p pid Display the current time, how long the system has been up, # of current users, average system load for the pass 1, 5 and 15 mins
lsof
uptime
Runaway processes
Processes that consume excessive amounts of a system resource, such as CPU time or disk space
1. 2. 3.
4.
Periodic Processes
cron daemon
A daemon that run jobs periodically Crontab (/etc/crontab, /etc/cron.*/, /var/spool/cron/) $ crontab -l $ crontab -e
Format
Min Hour Day Month Weeday Command 10 23 * * mon-fri /home/weesan/backup/home.sh 30 23 * * fri /home/weesan/backup/import.sh 0 */1 * * * /usr/bin/rdate -s time.nist.gov
Reference
LAH