Scis.regis.edu ● [email protected] CS 468: Advanced UNIX Class 4 Dr. Jesús Borrego Regis University...
-
Upload
alaina-wilkerson -
Category
Documents
-
view
214 -
download
0
Transcript of Scis.regis.edu ● [email protected] CS 468: Advanced UNIX Class 4 Dr. Jesús Borrego Regis University...
Topics
•Controlling Processes•Periodic Processes•Process Management•Q&A•Midterm
2
Process
•A running program•Used to control resource allocation by the
OS•When a process is created, a table is
made in a Process Table•Process consists of address space and
memory pages allocated to the process•Address space has code, variables, stacks,
virtual memory pointers, and other data
4
Processes
5
A process can be defined as:
Source: Operating Systems: Internals and Design Principles (7th. Ed.) by William Stallings
Process data structures
•Address space map for process•Process state•Execution priority•Resources allocated and in use•File descriptors and network ports used•Process signal mask•Process owner
6
Processes
7
Threads
•Created by a fork in a process•Inherits from parent•Can have multiple threads executing
concurrently•Multicore and multiprocessor systems
benefit multithreading
8
Attributes
•PID – unique process ID•PPID – parent PID•UID – user ID; who created the process•EUID – effective UID – reflects resources the
process can have; same as UID in most casesGID – group ID
•EGID – effective GID•Niceness – how the process interacts with
others•Control terminal – linkages to standard I/O
9
Process lifecycle
•Created with fork•Process execution begins with exec•Process terminates with a call to exit
▫Provides return code (0 is success)▫Parent receives return code to
acknowledge child’s death•If parent dies first, child is “adopted” by
init
10
Signals
•Interrupt request for processes•Can be used to communicate among
processes•Can kill, interrupt, or suspend processes•Can be originated by kernel when
unhandled exceptions occur•When received, a handler is called (if
handler is defined); otherwise, kernel takes action
11
Kill signal
•Used to terminate a process•Can be used by normal users to kill their
own processes•Root access is required for other
processes•Kill receives a signal, a numeric value
(see previous slide)•In some systems, killall terminates init –
system shutdown
13
Monitoring processes•To monitor processes:
ps•Shows PID, UID,
priority, control terminal
•Can include memory used, CPU utilization, status
•See example of ps aux on page 131
16
Dynamic Monitoring
•ps captures a snapshot of the system▫At that particular time
•top – top processes using the system every 10 seconds (default)
•topas – AIX version•prstat – Solaris version
20
/proc File System
•The /proc directory contains information about the system state
•The kernel creates the directory•Information is organized by
subdirectories named by the PID▫/proc 1 is the init process directory
•Predefined directories are shown in Table 5.7 (next slide)
21
Tracing signals and system calls•Linux provides visibility into a process
with strace▫Shows every system call and every signal
received•Similar: truss (AIX, Solaris), and tusc
(HPUX)•Example of strace is shown on page 137
24
Scheduling Commands
26
•To schedule scheduled processes: cron daemon
•Starts when system boots up and terminates when shutdown
•Receives configuration files (crontab) with commands and times to execute▫User crontabs located /var/spool/cron▫One for root, up to one per user
•Executes lines with sh
crontab File Format
27
•#comments•Six field line:
▫Minute, hour, day of month, month, weekday (separated by white space)
▫Command (passed to shell in entirety)•% represent new lines
▫Command receives characters up to first %
Time Formats
29
•* - wild card•Single integers – matches exactly•Two integers separated by dash – range•Ranges followed by slash and step:
▫1-10/2 1 to 10, in 2 increments•Comma separated list of values
35 10 * * 1-3 10:35 am Monday to Wednesday
crontab Management
31
•To create or replace your user’s crontab:crontab filename
•To check out crontab and edit:crontab -e
•To list contents of crontab:crontab -l
•To remove crontab:crontab –r
•Roots can add username to above
Applications of cron
32
•Preinstalled: ▫Daily scripts in /etc/cron.daily▫Weekly scripts in /etc/cron.weekly
•Reminders: periodic tasks•Filesystem cleanup
▫Removing obsolete files•Network file synchronization•Log file cleanup
Process Management
33
•Kernel controls process access to RAM and CPU:▫Scheduler – allocates CPU time to a
processes, based on scheduling algorithm▫Memory Manager – allocates memory
space to each process and protects it from external source access
CPU Utilization
34
Scheduling of processes
35
Source: Operating Systems: Internals and Design Principles (7th. Ed.) by William Stallings
Executable file layout
36
Magic Number and Main Header
Section One Header
Section Two Header
Section One
Section Two
First Processes
•PID 0 (sched) – created at boot•PID 0 executes fork and exec twice to
create processes 1 (init) and 2 (pageout)
37
Process 1
fork/exec fork/exec
process 48 process 12
process 34
fork/exec
Process States
38
RunningZombie
dRunnabl
eIdle
Sleeping
Suspended
Initialize
Signal Signal
Exit
Wait on Event
EventOccurs
AllocatedCPU
Process Composition
•Code Area – executable portion of the process
•Data Area – static data used by process•Stack Area – Temporary data•User Area – Housekeeping process
information•Page Tables – Memory management
system
39
User Area
•One per process•Accessible by the kernel•Fields included:
▫Signal handling record▫File descriptor record▫CPU access record
40
Process Table
•One entry for each process•Created in kernel’s data region•Contain:
▫PID and PPID▫UID and GID▫Process state▫Location of code, data, stack, user area▫Pending signal set
41
Questions?
43