































Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
A set of slides from a course on Operating Systems at Cornell University. It covers the concepts of processes and threads, including what a process is, how to create and manage processes, and the life cycle of a process. The slides also cover system call interfaces, creating a process via CreateProcess and fork, and built-in UNIX shell commands. code examples and possible outputs.
Typology: Slides
1 / 39
This page cannot be seen from the preview
Don't miss anything!
































What is a Process?
Who should be allowed to start a process? Possibility #1: Only the kernel may start a process Possibility #2: User-level processes may start processes
System Call Interface System Call Interface Portable Operating System Kernel Portable OS Library Compilers Web Servers Source Code Control Web Browsers Email Databases Word Processing x86 ARM PowerPC 10Mbps/100Mbps/1Gbps Ethernet 802.11 a/b/g/n SCSI IDE Graphics Accelerators LCD Screens Why so skinny? Example: Crea%ng a Process Windows: CreateProcess(…); UNIX fork + exec
Abstract Life of a Process New Runnable Running Zombie Waiting admiSed done I/O CompleOon I/O OperaOon dispatch interrupt, descheduling Details on Thursday.
CreateProcess (Simplified) System Call if (!CreateProcess( NULL, // No module name (use command line) argv[1], // Command line NULL, // Process handle not inheritable NULL, // Thread handle not inheritable FALSE, // Set handle inheritance to FALSE 0, // No creation flags NULL, // Use parent's environment block NULL, // Use parent's starting directory &si, // Pointer to STARTUPINFO structure &pi ) // Ptr to PROCESS_INFORMATION structure ) [Windows]
Beginning a Process via CreateProcess Fork Kernel has to:
Code example
Possible outputs?
QuesOons
What is a Shell? Job control system
Signals [UNIX] 16 ID Name^ Default Action^ Corresponding Event 2 SIGINT^ Terminate^ Interrupt (e.g., ctrl-c from keyboard) 9 SIGKILL^ Terminate^ Kill program (cannot override or ignore) 14 SIGALRM^ Terminate^ Timer signal 17 SIGCHLD^ Ignore^ Child stopped or terminated 20 SIGTSTP^ Stop until next SIGCONT Stop signal from terminal (e.g. ctrl-z from keyboard) A virtualized interrupt. Allow applica5ons to behave like opera5ng systems. youtube?
Sending a Signal Kernel delivers a signal to a des5na5on process For one of the following reasons:
Signal Example 19 void int_handler(int sig) { printf("Process %d received signal %d\n", getpid(), sig); exit(0); } int main() { pid_t pid[N]; int i, child_status; signal(SIGINT, int_handler); for (i = 0; i < N; i++) // N forks if ((pid[i] = fork()) == 0) { while(1); //child infinite loop } for (i = 0; i < N; i++) { // parent continues executing printf("Killing proc. %d\n", pid[i]); kill(pid[i], SIGINT); } for (i = 0; i < N; i++) { pid_t wpid = wait(&child_status); if (WIFEXITED(child_status)) // parent checks for each child’s exit printf("Child %d terminated w exit status %d\n", wpid, WEXITSTATUS(child_status)); else printf("Child %d terminated abnormally\n", wpid); } exit(0); }
Blocked Signals A process can block the receipt of certain signals