CHAPTER 8 299 310 333 345 John Carelli
- Slides: 19
CHAPTER 8 (299 -310, 333 -345) John Carelli, Instructor Kutztown University carelli@kutztown. edu 1
Definition - execution of a command PID - Process IDentification number Hierarchical structure processes can spawn children (sub-processes) pstree command CSC 252: John Carelli Source: Dr. Lisa Frye (modified) 2
https: //goo. gl/images/381 Bd. N CSC 252: John Carelli Source: Dr. Lisa Frye (modified) 3
Definition - the lifetime of a user login process job - a command pipeline (which may be a simple command) ; - command separator & - run in the background CSC 252: John Carelli Source: Dr. Lisa Frye (modified) 4
history - log of past commands jobs - currently running jobs kill, (stop, in tcsh) - terminate a process fg, bg - move process to foreground/background ps - list processes top - view top running processes uptime - time the system has been up and running free - report on available memory pstree - show process tree nohup - run command immune to hangups CSC 252: John Carelli Source: Dr. Lisa Frye (modified) 5
ps command Used to view processes Unix, BSD, and GNU (long format) options Unix: single dash BSD: no dash GNU double dash Current user’s processes ps ux ps –ly (or ps –F …) All user’s processes ps aux ps –ely Note: these output different information! CSC 252: John Carelli Source: Dr. Lisa Frye (modified) 6
strace - trace system calls on a command truss (not implemented) is similar gprof (prof) - compile c/c++ programs with –gp option - run gprof on executable to get profile - see profile. c example CSC 252: John Carelli Source: Dr. Lisa Frye (modified) 7
fc –l List commands from history fc –e emacs Use emacs to edit and reexecute previous command fc –s <num> Reexecute command number <num> fc –s <old_string> = <new_string> <num> Reexecute command number <num> after changing <old_string> to <new_string> CSC 252: John Carelli Source: Dr. Lisa Frye (modified) 8
dirs - display directory stack pushd - push a directory on to stack (and go there) popd CSC 252: John Carelli - pop a directory from the stack (and go there) Source: Dr. Lisa Frye (modified) 9
Data Structure in RAM Contains info about the following: PID PPID (parent) Real and effective UID and GID Process state Location of its code, data, stack and user area List of all pending signals CSC 252: John Carelli Source: Dr. Lisa Frye (modified) 10
init - last step in boot process (creates id “ 1”) fork(), exec() - spawn new processes (see fork. c and doexec. c examples) getty - create terminal session (mingetty) login - login a user Modes User kernel CSC 252: John Carelli - “normal” user - root Source: Dr. Lisa Frye (modified) 11
Termination status Normal Abnormal wait() - process runs to normal completion - terminated externally (ex: kill -9) - “C” system call - parent suspends … waits for status of child to change - see waitpid. c example Zombie process - terminated, but still in process table - exists so parent can read exit code - can’t kill it with kill command (see zombie. c) Orphan process CSC 252: John Carelli - parent terminated (intentional or not) - init process becomes parent (see orphan. c) Source: Dr. Lisa Frye (modified) 12
To see status codes: ps -o uid, pid, stat, cmd Codes: D Uninterruptible sleep (usually IO) R Running or runnable (on run queue) S Interruptible sleep T Stopped Z Defunct ("zombie") process Additional info: < high-priority (not nice to other users) N low-priority (nice to other users) L has pages locked into memory (for IO) s is a session leader + is in the foreground process group Idle/Waiting (for an event) Suspended / Stopped Runnable / Ready Exit Running Zombie Sleeping / Blocked CSC 252: John Carelli Source: Dr. Lisa Frye (modified) 13
User Code area- program instructions Data area - program data Stack area - program stack (manage function calls) User area - housekeeping (open files, current directory…) Kernel area Process Table Page Table CSC 252: John Carelli Source: Dr. Lisa Frye (modified) 14
Scheduler decides which processes to run and for how long uses preemptive multitasking – system decides (cooperative is the other choice – process “yields”) Memory manager virtual memory system looks like it has more actual memory pages, page tables Magic number embedded near beginning of file – indicates file type file command uses it to identify type CSC 252: John Carelli Source: Dr. Lisa Frye (modified) 15
Multilevel Priority Queue scheduling algorithm Process’ s priority processes get a priority number ex: ps -o uid, ppid, pri, ni, cmd Higher priority # means lower priority “niceness” Nice value (nice, renice -n) 20 is nice, -20 is not, 0 default Context switch save the process state restore it later CSC 252: John Carelli Source: Dr. Lisa Frye (modified) 16
Pages (stored in memory) Region table (inode ptrs, page table ptrs, process #’s, …) pregion – process region (text/data/stack. . . ) Page table Modified bit Referenced bit Age (“dirty bit” – checks for data modification) (set when referenced, periodically cleared) (LRU – least recently used) RAM table (paging DS in RAM) Page daemon (paging mgmt. process) Swap space (program moved to disk) Page fault (page not in memory) CSC 252: John Carelli Source: Dr. Lisa Frye (modified) 17
Delayed Execution crontab run jobs on a schedule sets up tables for the cron daemon to open editor: crontab –e at execute a command at a specific time output gets mailed to you (via unix mail) CSC 252: John Carelli Source: Dr. Lisa Frye (modified) 18
Signals and Sockets Assign a signal handler with signal() Example: timeout. c Send signals between processes Example: sig. Talk. c Interprocess server/client communication via a socket Socket is a combination of an IP address and a port Example: server. c and client. c (with makefile) http: //www. cs. rpi. edu/~moorthy/Courses/os 98/Pgms/socket. html CSC 252: John Carelli Source: Dr. Lisa Frye (modified) 19