DOC PREVIEW
Princeton COS 217 - Processes

This preview shows page 1 out of 4 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 4 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 4 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

1ProcessesCS 2172Operating System• Supports virtual machines Promises each process the illusion of having whole machine to itself• Provides services: Protection Scheduling  Memory management File systems Synchronization etc.HardwareOS KernelUserProcessUserProcess3What is a Process?• A process is a running program with its own … Processor state– EIP, EFLAGS, registers Address space (memory)– Text, bss, data, heap, stackHardwareOS KernelUserProcessUserProcess4Operating System• Common implementation strategies Chop up resources into small pieces andallocate small pieces at fine-grain level Introduce level of indirection and provide mapping from virtual resources to physical ones Use past history to predict future behaviorHardwareOS KernelUserProcessUserProcess5Life Cycle of a Process• Running: instructions are being executed• Waiting: waiting for some event (e.g., i/o finish) • Ready: ready to be assigned to a processorCreate Ready Running TerminationWaiting6Context SwitchRunningRunningSave contextLoad contextSave contextLoad context......RunningWaitingWaitingWaitingProcess AProcess B7Overlap CPU with I/O operations• Schedule CPU for process B while process A is waiting for I/O Better utilize CPUCPUCPUCPUI/OI/O I/OA:CPUCPUCPUI/OI/O I/OB:8Process Control Block• For each process, the kernel keeps track of ... Process state (new, ready, waiting, halted) CPU registers (EIP, EFLAGS, EAX, EBX, …) CPU scheduling information (priority, queues, ...) Memory management information (page tables, ...) Accounting information (time limits, group ID, ...) I/O status information (open files, I/O requests, ...)9Fork• Create a new process (system call) child process inherits state from parent process parent and child have separate copies of that state parent and child share access to any open filespid = fork();if (pid != 0) {/* in parent */...} else {/* in child */...}ParentChild10Wait• Parent waits for a child (system call) blocks until a child terminates returns pid of the child process returns –1 if no children exists (already exited) status#include <sys/types.h>#include <sys/wait.h>pid_t wait(int *status);• Parent waits for a specific child to terminate#include <sys/types.h>#include <sys/wait.h>pid_t waitpid(pid_t pid, int *status, int options);11Fork•Inherited: user and group IDs signal handling settings  stdio file pointers current working directory root directory file mode creation mask  resource limits  controlling terminal all machine register states  control register(s) . . .•Separate in child process ID  address space (memory) file descriptors parent process ID  pending signals  timer signal reset times . . .12Exec• Overlay current process image with a specified image file (system call) affects process memory and registers has no affect on file table• Example:execlp(“ls”, “ls”, “-l”, NULL);fprintf(stderr, “exec failed\n”);exit(1);13Exec (cont)• Many variations of execint execlp(const char *file,const char *arg, ...)int execl(const char *path,const char *arg, ...)int execv(const char *path,char * const argv[])int execle(const char *path,const char *arg, ...,char * const envp[])• Also execve and execvp14Fork/Exec• Commonly used together by the shell... parse command line ...pid = fork() if (pid == -1)fprintf(stderr, “fork failed\n”);else if (pid == 0) {/* in child */execvp(file, argv);fprintf(stderr, “exec failed\n”);} else {/* in parent */pid = wait(&status);}... return to top of loop ...cshforkexecvplswait15System• Convenient way to invoke fork/exec/wait Forks new process Execs command  Waits until it is completeint system(const char *cmd);• Example:int main(){system(“echo Hello world”);}16Summary• Operating systems manage resources Divide up resources (e.g., quantum time slides) Allocate them (e.g., process scheduling)• A processes is a running program with its own … Processor state Address space (memory)• Create and manage processes with ... fork exec wait system}Used in


View Full Document

Princeton COS 217 - Processes

Documents in this Course
Summary

Summary

4 pages

Lecture

Lecture

4 pages

Generics

Generics

14 pages

Generics

Generics

16 pages

Lecture

Lecture

20 pages

Debugging

Debugging

35 pages

Types

Types

7 pages

Lecture

Lecture

21 pages

Assembler

Assembler

16 pages

Lecture

Lecture

20 pages

Lecture

Lecture

39 pages

Testing

Testing

44 pages

Pipeline

Pipeline

19 pages

Lecture

Lecture

6 pages

Signals

Signals

67 pages

Building

Building

17 pages

Lecture

Lecture

7 pages

Modules

Modules

12 pages

Generics

Generics

16 pages

Testing

Testing

22 pages

Signals

Signals

34 pages

Lecture

Lecture

19 pages

Load more
Download Processes
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Processes and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Processes 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?