Controlling%20Processes%20 - PowerPoint PPT Presentation

About This Presentation
Title:

Controlling%20Processes%20

Description:

Controlling Processes – PowerPoint PPT presentation

Number of Views:30
Avg rating:3.0/5.0
Slides: 16
Provided by: wee65
Learn more at: http://alumni.cs.ucr.edu
Category:

less

Transcript and Presenter's Notes

Title: Controlling%20Processes%20


1
Controlling Processes Periodic Processes
  • WeeSan Lee ltweesan_at_cs.ucr.edugt
  • http//www.cs.ucr.edu/weesan/cs183/

2
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
  • QA

3
What is a process?
  • A running program
  • Information of a process
  • PID
  • PPID
  • UID EUID (used for access permission)
  • GID EGID (used for access permission)
  • Status
  • Niceness or nice value

4
What is a setuid process?
  • A regular process
  • EUID UID of the user who runs the
    command/script
  • A setuid process
  • EUID the owner UID of the setuid
    command/script
  • How to find setuid programs?
  • find /bin -perm -4000 xargs ls -l
  • -rwsr-xr-x 1 root root 57908 Nov 30 1435
    /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 1435
    /bin/umount

5
How to create a process?
  • emacs

// Bash clone switch (fork()) case -1 //
Error break case 0 // Child
execv("emacs", ) break default // Parent
wait() break
// Bash switch (fork()) case -1 // Error
break case 0 // Child execv("emacs", ...)
break default // Parent wait() break
6
Signals
  • Process-level interrupt requests
  • 30 signals
  • kill -l
  • Can be caught or trapped by a process
  • In Bash, we do
  • trap done2() exit 0 1 2 3 15
  • Can be blocked or ignored

7
Signals (cont)
  • Common signals
  • 1 HUP
  • 2 INT
  • Ctrl-C
  • 3 QUIT
  • Core dumping
  • 9 KILL
  • 15 TERM
  • STOP
  • TSTP
  • Ctrl-Z
  • CONT
  • USR1
  • USR2

8
How to send signals to the processes?
  • kill -signal pid
  • Default signal is TERM or 15
  • ps auxw grep emacs
  • weesan 857 0.0 0.0 13312 7952 pts/5 S Apr15 005
    emacs
  • kill -9 857
  • killall -signal process_name
  • killall -9 emacs

9
Process States
  • Runnable (R)
  • Ready to be executed
  • Sleeping (S)
  • Get no CPU time until receiving a signal
  • Zombie (Z)
  • Exited process whose status hasnt been
    collected
  • Display as ltdefunctgt on ps,
  • Stopped (T)
  • Process stopped by STOP or TSTP signal

10
Niceness
  • -20 to 19
  • A high nice value means a low priority
  • Inherited from the parent
  • Can increase but not decrease
  • Except for root
  • For example
  • nice -n 1 program
  • renice 1 pid

11
Monitor Processes
  • ps
  • A tool for monitoring processes, eg.
  • ps auxw less
  • ps laxw less
  • ps auxw awk -F' ' ' print 1, 2, 10 '
  • weesan 560 228
  • weesan 563 000
  • top
  • A good tool to display CPU usage
  • top
  • top -n 1

12
Monitor Processes (cont)
  • strace
  • Show every system call and signal a process
    receives
  • strace -p pid
  • lsof
  • List open files
  • lsof -u userid
  • lsof -p pid
  • uptime
  • 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

13
Monitor Processes (cont)
  • Runaway processes
  • Processes that consume excessive amounts of a
    system resource, such as CPU time or disk space
  • How to approach them?
  • Use ps, top, strace, lsof to locate them
  • renice them
  • Stop them by sending STOP signal and resume later
    by CONT signal
  • kill them

14
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

15
Reference
  • LAH
  • Ch 4 Controlling Processes
  • Ch 8 Periodic Processes
Write a Comment
User Comments (0)
About PowerShow.com