The Life and Death of A Process

Size: px
Start display at page:

Download "The Life and Death of A Process"

Transcription

1 COMP 111: Operating Systems (Fall 2013) The Life and Death of A Process Noah Mendelsohn Tufts University noah@cs.tufts.edu Web: Based on a presentation by Professor Alva Couch Copyright 2013 Noah Mendelsohn

2 Today How processes are created, managed and terminated Sharing the computer (redux) From file.c to a.out to running image Library routines and shared libraries 2

3 Review: Processes & the Kernel 3

4 Operating systems do two things for us: They make the computer easier to use The facilitate sharing of the computer by multiple programs and users 4

5 actually, Unix & Linux have one more goal: To facilitate running the same program (and OS!) on different types of computer 5

6 The protected OS Kernel Multiple Programs Running at once The operating system is a special, privileged program, with its own code and data. We call the protected, shared part of the OS the kernel. MAIN MEMORY Angry Birds Play Video Browser OPERATING SYSTEM KERNEL CPU

7 We need help from the hardware to protect the kernel! The hardware has memory mapping features that the OS can use to: Hide the kernel from other programs Hide programs from each other Convince each program it s got its own private memory starting at address zero MAIN MEMORY Angry Birds Play Video Browser OPERATING SYSTEM KERNEL CPU

8 Privileged instructions only the OS can use The hardware has special instructions that only the kernel can use to: * Initiate I/O * Set clocks and timers * Control memory mapping The Kernel runs in privileged or kernel or supervisor Angry state. Birds Play Video Browser MAIN MEMORY OPERATING SYSTEM KERNEL CPU Ordinary programs run in user mode. If a user program tries a privileged operation, the hardware will tell the kernel!

9 A process is an instance of a running program Angry Birds Play Video Browser OPERATING SYSTEM KERNEL MEMORY Keyboard, mouse,display CPU Disk Printer

10 A process is an instance of a running program How does this process get started? How does the OS know what code to run? Angry Birds Play Video Browser OPERATING SYSTEM KERNEL MEMORY Keyboard, mouse,display CPU Disk Printer

11 Today How processes are created, managed and terminated Sharing the computer (redux) From file.c to a.out to running image Library routines and shared libraries 11

12 Cloning a Process with fork 12

13 Process creation in Unix/Linux Each process starts life as a clone of its parent Use the fork() system call to create a clone When it s born, each process inherits from its parent Open files (related processes share a file pointer) Environment variables Many other things: e.g. current directory An exact copy of all memory segments from the parent The same code running at the same place, I.E. dropping through the fork! Each copy can tell whether it is parent or child Parent gets process ID as return value from fork Child gets zero 13

14 Example of fork() system call int main(int argc, char *argv[]) { pid_t child_pid; /* child s process id or zero */ fprintf(stderr,"parent: Parent has started\n"); child_pid = fork(); } if (child_pid) { fprintf(stderr, "PARENT: my pid is %d and my parent is %d\n", getpid(), getppid()); wait(child_pid); fprintf(stderr,"parent: my child with pid=%d has died\n", child_pid); } else { fprintf(stderr,"child: my pid is %d and my parent is %d\n", getpid(), getppid()); } Using stderr instead of stdout because it s unbuffered output is never delayed 14

15 Example of fork() system call Print startup message and fork into two processes a parent and a child int main(int argc, char *argv[]) { pid_t child_pid; /* child s process id or zero */ fprintf(stderr,"parent: Parent has started\n"); child_pid = fork(); } if (child_pid) { fprintf(stderr, "PARENT: my pid is %d and my parent is %d\n", getpid(), getppid()); wait(child_pid); fprintf(stderr,"parent: my child with pid=%d has died\n", child_pid); } else { fprintf(stderr,"child: my pid is %d and my parent is %d\n", getpid(), getppid()); } Using stderr instead of stdout because it s unbuffered output is never delayed 15

16 Example of fork() system call int main(int argc, char *argv[]) The parent gets the child s process id..the child { gets zero. pid_t child_pid; /* child s process id or zero */ fprintf(stderr,"parent: Parent has started\n"); child_pid = fork(); } if (child_pid) { fprintf(stderr, "PARENT: my pid is %d and my parent is %d\n", getpid(), getppid()); wait(child_pid); fprintf(stderr,"parent: my child with pid=%d has died\n", child_pid); } else { fprintf(stderr,"child: my pid is %d and my parent is %d\n", getpid(), getppid()); } Using stderr instead of stdout because it s unbuffered output is never delayed 16

17 Example of fork() system call In the parent int main(int argc, char *argv[]) { Print a message pid_t child_pid; /* child s Wait process for the id child or to zero complete */ its work Announce that the child has been reaped fprintf(stderr,"parent: Parent Exit has (drop started\n"); through) child_pid = fork(); } if (child_pid) { fprintf(stderr, "PARENT: my pid is %d and my parent is %d\n", getpid(), getppid()); wait(child_pid); fprintf(stderr,"parent: my child with pid=%d has died\n", child_pid); } else { fprintf(stderr,"child: my pid is %d and my parent is %d\n", getpid(), getppid()); } Using stderr instead of stdout because it s unbuffered output is never delayed 17

18 Example of fork() system call int main(int argc, char *argv[]) { In the child pid_t child_pid; /* child s process id or zero */ Print a message fprintf(stderr,"parent: Parent has started\n"); Exit child_pid = fork(); } if (child_pid) { fprintf(stderr, "PARENT: my pid is %d and my parent is %d\n", getpid(), getppid()); wait(child_pid); fprintf(stderr,"parent: my child with pid=%d has died\n", child_pid); } else { fprintf(stderr,"child: my pid is %d and my parent is %d\n", getpid(), getppid()); } Using stderr instead of stdout because it s unbuffered output is never delayed 18

19 Example of fork() system call int main(int argc, char *argv[]) Remember: { pid_t child_pid; /* child s On a process multi-core id machine, or zero the */ parent and the child may really be running at the same time! fprintf(stderr,"parent: Parent has started\n"); child_pid = fork(); } if (child_pid) { fprintf(stderr, "PARENT: my pid is %d and my parent is %d\n", getpid(), getppid()); wait(child_pid); fprintf(stderr,"parent: my child with pid=%d has died\n", child_pid); } else { fprintf(stderr,"child: my pid is %d and my parent is %d\n", getpid(), getppid()); } Using stderr instead of stdout because it s unbuffered output is never delayed 19

20 Example of fork() system call OUTPUT $ fork1 PARENT: Parent has started int main(int argc, char *argv[]) PARENT: my pid is and my parent { is pid_t child_pid; /* child s process CHILD: my id pid or zero is */ and my parent is fprintf(stderr,"parent: Parent has started\n"); child_pid = fork(); PARENT: my child with pid=26930 has died $ } if (child_pid) { fprintf(stderr, "PARENT: my pid is %d and my parent is %d\n", getpid(), getppid()); wait(child_pid); fprintf(stderr,"parent: my child with pid=%d has died\n", child_pid); } else { fprintf(stderr,"child: my pid is %d and my parent is %d\n", getpid(), getppid()); } Using stderr instead of stdout because it s unbuffered output is never delayed 20

21 Example of fork() system call int main(int argc, char *argv[]) { Question? What s the parent s parent? pid_t child_pid; /* child s process id or zero */ fprintf(stderr,"parent: Parent has started\n"); child_pid = fork(); } if (child_pid) { fprintf(stderr, "PARENT: my pid is %d and my parent is %d\n", getpid(), getppid()); wait(child_pid); fprintf(stderr,"parent: my child with pid=%d has died\n", child_pid); } else { fprintf(stderr,"child: my pid is %d and my parent is %d\n", getpid(), getppid()); } Using stderr instead of stdout because it s unbuffered output is never delayed 21

22 $ ps PID TTY TIME CMD pts/22 00:00:00 tcsh pts/22 00:00:00 ps int main(int argc, char *argv[]) $ { $ pid_t child_pid; /* child s $ fork1 process id or zero */ PARENT: Parent has started fprintf(stderr,"parent: PARENT: Parent has my pid started\n"); is and my parent is CHILD: my pid is and my parent is child_pid = fork(); PARENT: my child with pid=26930 has died $ Most commands have the shell as a parent! Example of fork() system call } if (child_pid) { fprintf(stderr, "PARENT: my pid is %d and my parent is %d\n", getpid(), getppid()); wait(child_pid); fprintf(stderr,"parent: my child with pid=%d has died\n", child_pid); } else { fprintf(stderr,"child: my pid is %d and my parent is %d\n", getpid(), getppid()); } Using stderr instead of stdout because it s unbuffered output is never delayed 22

23 Some things to note about fork Code for parent and child is the same we haven t learned to run another program yet Parent and child run in parallel Child gets a copy of variables changes are not seen by the parent There is a tree of processes rooted at a special system init process, which is always pid=1 every process except init has a parent! Parent must wait for the child to die or it becomes a zombie 23

24 Zombies, process IDs and the process table Every process has an ID (you ve seen that) Inside the kernel, there is a data structure known as a process descriptor for each process that hasn t been reaped by a wait call from the parent On 32 bit Linux systems, there are typically process IDs if they get used up, the system can t make new processes Process IDs and descriptors can t be reused until the parent has waited Therefore: be sure to wait for the death of every process you create! What happens if the parent dies without waiting? Children get inherited by init, which will reap them The big problem is if you keep running and don t reap your children! 24

25 Killing a process Send the process a kill signal to ask/tell it to die How? From another process: kill(victim_pid, SIGKILL) system call From the console: kill -9 victim_pid SIGKILL (integer value -9) is a magic signal that the victim cannot intercept: it will kill the process immediately Other signals are used for many purposes...covered next week The parent still must wait/reap or the result is a zombie the shell will reap processes of commands it launches 25

26 Brief Interlude What s a Signal 26

27 Review: How can your process call the kernel? Your program can use system calls to ask the kernel Angry Birds for service (e.g. read, kill, etc.) Play Video Browser Filesystem, Graphics System, Window system, TCP/IP Networking, etc., etc. OPERATING SYSTEM KERNEL MEMORY Keyboard, mouse,display CPU Disk Printer

28 Signals: How the kernel can call your program! Before signal can be caught, child must issue to identify the handler function: The kernel can cause a preset signal handler in your program to run this alerts your program to some news from the kernel Parent signal(signame, handler_function) If no handler, OS supplies default behavior Child OPERATING SYSTEM KERNEL MEMORY CPU

29 Signal handling example /* sigalarm.c */ #include <stdio.h> #include <signal.h> typedef enum { false, true } bool; timeisup is the signal handler int sleeping = false; void timeisup(int sig) { fprintf(stderr, "Quit bothering me, I was sleeping!\n", sig); sleeping = false; } main() { signal(sigalrm,timeisup); alarm(5); /* Please wake me in 5 seconds */ sleeping = true; while (sleeping) { printf("zzz...\n"); sleep(1); } Tell the OS to call the timeisup function when the alarm signal arrives. } fprintf(stderr, "Dang, you woke me up!\n"); 29

30 Signal handling example /* sigalarm.c */ #include <stdio.h> #include <signal.h> typedef enum { false, true } bool; int sleeping = false; void timeisup(int sig) { fprintf(stderr, "Quit bothering me, I was sleeping!\n", sig); sleeping = false; } main() { signal(sigalrm,timeisup); alarm(5); /* Please wake me in 5 seconds */ sleeping = true; while (sleeping) { printf("zzz...\n"); sleep(1); } Tell the OS to send SIGALRM in 5 seconds } fprintf(stderr, "Dang, you woke me up!\n"); 30

31 Signal handling example /* sigalarm.c */ #include <stdio.h> #include <signal.h> typedef enum { false, true } bool; QUESTION: does sleeping ever become false? int sleeping = false; void timeisup(int sig) { fprintf(stderr, "Quit bothering me, I was sleeping!\n", sig); sleeping = false; } main() { signal(sigalrm,timeisup); alarm(5); /* Please wake me in 5 seconds */ sleeping = true; while (sleeping) { printf("zzz...\n"); sleep(1); } Loop printing zzz } fprintf(stderr, "Dang, you woke me up!\n"); 31

32 Signal handling example /* sigalarm.c */ #include <stdio.h> YES!! #include When <signal.h> the signal arrives! typedef enum { false, true } bool; QUESTION: does sleeping ever become false? int sleeping = false; void timeisup(int sig) { fprintf(stderr, "Quit bothering me, I was sleeping!\n", sig); sleeping = false; } main() { signal(sigalrm,timeisup); alarm(5); /* Please wake me in 5 seconds */ sleeping = true; while (sleeping) { printf("zzz...\n"); sleep(1); } } fprintf(stderr, "Dang, you woke me up!\n"); 32

33 Signal handling example /* sigalarm.c */ #include <stdio.h> #include <signal.h> typedef enum { false, true } bool; volatile sigatomic_t sleeping = false; main() { signal(sigalrm,timeisup); alarm(5); /* Please wake me in 5 seconds */ } sleeping = true; while (sleeping) { printf("zzz...\n"); sleep(1); } fprintf(stderr, "Dang, you woke me up!\n"); Advanced topic On most machines, this will work fine if you declare sleeping as an int, however There are two issues in principle: 1) The compiler working on main() needs to know that sleeping could get updated void timeisup(int sig) { fprintf(stderr, "Quit bothering me, I was sleeping!\n", by code it s sig); not seeing (the handler volatile warns it) sleeping = false; } 2) For some data types, updating a value takes multiple instructions, and the alarm could ring while the data is in an inconsistent state. Very unlikely for an int, but sigatomic_t is guaranteed to be updated atomically Glad you asked? Lesson: asynchronous programming is tricky, and OS s do it all the time! 33

34 One process can ask kernel to signal another Parent Child OPERATING SYSTEM KERNEL MEMORY CPU

35 One process can ask kernel to signal another Before signal can be caught, child must issue: kill(sig_xxxx, child_pid) Oddly, kill is used not just for kill signals, but for all signals! Parent signal(sig_xxxx, handler_function) If no handler, OS supplies default behavior Child handler_function()called OPERATING SYSTEM KERNEL MEMORY CPU

36 One process can ask kernel to signal another Before signal can be caught, child must issue: kill(sig_stp, child_pid) Oddly, kill is used not just for kill signals, but for all signals! Parent signal(signame, handler_function) If no handler, OS supplies default behavior Child OPERATING SYSTEM KERNEL By the way, the shell has a kill command you can use to send signals to any of your processes (or other people s MEMORY processes if you have permission). Use man 1 kill for more info on the shell command, and man 2 kill & man 2 signal for the system calls. CPU

37 Background and suspended processes From most shells: emacs myfile.txt shell (parent process) stays busy while Emacs runs emacs myfile.txt & & says: run in background: let shell run while Emacs runs If you start a program in the foreground and want to do something else emacs myfile.txt shell (parent process) stays busy while Emacs runs CTRL-Z: suspend Emacs and let shell run Choices after CTRL-Z: fg puts job back in foreground; bg resumes it in background To find out about running background jobs Run the jobs command Each job is named: %1, %2, etc. You can do things like kill -9 %1 or fg %2 Most of this is implemented with signals (e.g. CTRL-Z sends SIGSTP which by default pauses the process) so you can do this from a program as well as from the shell Summary from Prof. Couch: typing./a.out in the shell is an explicit wait. typing./a.out & in the shell is a background execution. 37

38 Running a new Program with fork and exec 38

39 Using exec to launch a new program Fork creates parallel copies of the same program Exec replaces the code for a process with a brand new program and calls its main function Common idiom: to run a new program fork() /* to create a child process */ exec() /* have the child replace itself with the program to be run */ [ optional: continue to do work in the parent while the child runs ] wait(): /* in the parent for the new program to complete */ Ever wondered where your return values from exit() go? The are available to the parent via: pid = wait(int *child_exit_status) So, the parent can find out if the child returned success or an error 39

40 Examples of fork/exec Example: running a "cat" command in the foreground: Example: running a "cat" command in the foreground with explicit wait: Example: running a "cat" command in the background with implicit wait: Example: running a user-typed command in the foreground without arguments: Example: running a user-typed command in the background without arguments: These examples are from Prof. Couch s lecture 40

41 Some things to watch with exec Read the man page to find out the arguments it takes there are several flavors As with fork, the new program retains: Open files, environment variables, current working directory, owner, etc., etc. All data and variables from the caller are replaced if you have buffered I/O that is be lost Consider the following: main() { printf("this won't get seen at all "); execl("/bin/cat", "cat", "/dev/null", 0); } // prints nothing at all, because // the execl erases the unwritten line buffer! 41

42 Some things to watch with exec Read the man page to find out the arguments it takes there are several flavors As with fork, the new program retains: Open files, environment variables, current working directory, owner, etc., etc. All data and variables from the caller are replaced if you have buffered I/O that will be lost Consider the following: By default, stderr does not buffer it s output as soon as you print it goes out. Try it! } main() { printf("this won't get seen at all "); fprintf(stderr, "this will get seen, because stderr flushes buffers on each write "); execl("/bin/cat", "cat", "/dev/null", 0); /* prints this will get seen, because stderr flushes buffers on each write */ /* the execl erases the unwritten stdout buffer, but the stderr output is already done */ 42

43 Today How processes are created, managed and terminated Sharing the computer (redux) From file.c to a.out to running image Library routines and shared libraries 43

44 Running, Runnable & Waiting Processes 44

45 Sharing the CPU Multiple Programs Running at once CPU is shared can only do one thing at a time* Angry Birds Play Video Browser OPERATING SYSTEM MAIN MEMORY CPU *Modern multi-core CPUs can schedule one process/core at a time

46 Process scheduling (For now, assume we have a simple one core CPU) If processes are ready to run, the OS picks one and runs it The chosen process is in the running state Processes have priority and high priority processes are run more often The others are marked as ready (or runnable) (I.e. they d like to run but need to wait their turn) Some processes are healthy but waiting for something Reasons: sleep(), waiting for I/O, wait(), select(), page fault These processes are in the blocked state and they aren t scheduled until that changes Multicore CPUs: exactly the same, but we can have one running process on each core! Designing process schedulers is an art. The strategy that gives good interactive response on a shared server may not be what you need for a massive database system! 46

47 The five state process model Run queue (processes in line for CPU) Dispatch Admit release New Ready Running Exit Timeout Blocked See: Stallings 7 th Edition Page

48 The five state process model In some OS s, a blocked process can die without running any cleanup. Run queue (processes in line for CPU) Dispatch Admit release New Ready Running Exit Timeout Blocked See: Stallings 7 th Edition Page

49 Sharing Memory 49

50 Sharing Memory All programs share memory Multiple Programs Running at once Angry Birds Play Video Browser OPERATING SYSTEM MAIN MEMORY CPU

51 Memory shortage What if we need more memory than we have? Angry Birds Play Video Browser C compiler Browser Emacs OPERATING SYSTEM MAIN MEMORY CPU

52 Swapping The OS can swap some process memory to disk Angry Birds Play Video Browser C compiler Browser Emacs OPERATING SYSTEM MAIN MEMORY CPU Disk

53 Swapping The OS can swap some process memory to disk Angry Birds Browser Browser Emacs OPERATING SYSTEM MAIN MEMORY CPU C compiler Play Video Disk

54 The five seven state process model Run queue (processes in line for CPU) Dispatch Admit Release New Ready Running Exit Timeout Ready / Suspend Blocked / Suspend Blocked See: Stallings 7 th Edition Page

55 The five seven state process model Run queue (processes in line for CPU) Processes that have been swapped to disk aren t scheduled Dispatch to run even if they re otherwise ready Admit Release New Ready Running Exit Timeout Ready / Suspend Blocked / Suspend Blocked See: Stallings 7 th Edition Page

56 Summary of paging and swapping 30 years ago, systems swapped whole processes Today, page-size chunks of memory are moved and mapped individually A process is often partially resident The scheduler blocks when a particular page that s needed is on disk On our systems, pagesize = 4096 bytes (try command: getconf PAGESIZE ) Special hardware is needed to make this work Real memory pages can be mapped to arbitrary locations in one or more virtual memories The hardware faults (tells the kernel) if a needed page is reference but not mapped Pages can be mapped read-only : fault if write is attempted The system tends to run well if the working sets of pages that programs reference a lot fit together in memory Historical reference: Denning, P.J. (1968), The working set model for program behavior. Communications of the ACM, 5/1968, Volume 11, pp

57 Copy on Write A Classic OS Optimization 57

58 Each process has its own virtual memory CPU MAIN MEMORY OPERATING SYSTEM Angry Birds Play Video Browser argv, environ Stack Call Stack) Heap (malloc d) Static uninitialized Data) Static initialized Data) Text code) 0 Angry Birds Virtual Memory 0xFFF FFFF

59 Each process has its own virtual memory CPU MAIN MEMORY OPERATING SYSTEM Angry Birds Consider what happens when we fork we ll need two complete copies of the whole process memory! Play Video Browser argv, environ Stack Call Stack) Heap (malloc d) Static uninitialized Data) Static initialized Data) Text code) 0 Angry Birds Virtual Memory 0xFFF FFFF

60 Fork needs to copy the virtual memory CPU MAIN MEMORY OPERATING SYSTEM Angry Birds Angry Birds argv, environ Stack Call Stack) Heap (malloc d) Static uninitialized Data) argv, environ Stack Call Stack) Heap (malloc d) Static uninitialized Data) 0xFFF FFFF Play Video Browser Static initialized Data) Text code) Static initialized Data) Text code) 0

61 Each process has its own virtual memory CPU MAIN MEMORY OPERATING SYSTEM Angry Birds argv, environ Stack Call Stack) Can we find a way to make the copy cheap? Angry Birds Heap (malloc d) Yes! Static uninitialized Data) argv, environ Stack Call Stack) Heap (malloc d) Static uninitialized Data) 0xFFF FFFF Play Video Browser Static initialized Data) Text code) Static initialized Data) Text code) 0

62 Each process has its own virtual memory CPU MAIN MEMORY OPERATING SYSTEM Map all the pages in both argv, environ argv, environ VMs to the same actual Angry Birds Angry Birds Stack Call Stack) pages in memory Heap (malloc d) Static uninitialized Data) Stack Call Stack) Heap (malloc d) Static uninitialized Data) 0xFFF FFFF Play Video Browser Static initialized Data) Text code) Static initialized Data) Text code) 0

63 Each process has its own virtual memory CPU MAIN MEMORY OPERATING SYSTEM Map all the pages in both argv, environ argv, environ VMs to the same actual Angry Birds Stack Call Stack) pages in memory and mark them all read only Angry Birds Heap (malloc d) Static uninitialized Data) Stack Call Stack) Heap (malloc d) Static uninitialized Data) 0xFFF FFFF Play Video Browser Static initialized Data) Text code) Static initialized Data) Text code) 0

64 Each process has its own virtual memory CPU MAIN MEMORY OPERATING SYSTEM Map all the pages in both Play Video argv, environ argv, environ VMs to the same actual Angry Birds Browser Stack Call Stack) pages in memory and mark them all read only Angry Birds Heap (malloc d) Static If either process changes (Angry uninitialized Birds Data) data, the OS will get the Static initialized write fault and Data) copy just the updated page! Text code) Stack Call Stack) Heap (malloc d) Static uninitialized Data) Static initialized Data) Text code) 0xFFF FFFF 0

65 Shared executables By the way: the same mapping tricks allow us to share a single copy of each executable (e.g. Emacs, gcc, firefox) This works even if they are launched using unrelated exec calls The system typically loads at most one copy of a given executable any later exec calls just map it! We can also share copies of libraries by using something called shared libraries we ll study those later today 65

66 Summary of copy on write A classic optimization used in many systems Hardware must support read-only mapping at the page level The time to clone a process or other data is small and often independent of the size Some work is necessary to set up the new maps: depends on the hardware Read-only data is never copied (e.g. the program code!) Writeable data is still not copied until it s actually updated 66

67 Sharing executable programs A similar trick is used to share the code for programs We ve seen how that works with fork(), but Even if lots of copies of a program are loaded independently using exec(), there s typically only one copy in memory or swapped to disk This is a huge savings. Think of how many times our Halligan homework server runs: bash, tcsh, gcc, make, emacs, vim There s typically just one loaded copy of each, no matter how many users Launching a new copy is very quick 67

68 Today How processes are created, managed and terminated Sharing the computer (redux) From file.c to a.out to running image Library routines and shared libraries 68

69 How do we get from source to executable program? 69

70 From source code to executable #include <stdio.h> int main(int argc, char *argv[]) { printf( The sum is %d\n sum(1,2)) } two_plus_one.c int sum(int a, int b) { return a+b; } arith.c gcc c arith.c gcc c two_plus_one.c Relocateable object code for sum() Relocateable object code for sum() arith.o two_plus_one.o 70

71 From source code to executable #include <stdio.h> int main(int argc, char *argv[]) { printf( The sum is %d\n sum(1,2)) } two_plus_one.c gcc c two_plus_one.c Relocatable.o files int sum(int a, int b) { return a+b; } Contain machine code References within the file are resolved References to external files not resolved arith.c Some address fields may need adjusting depending on final location in executable gcc c arith.c program Relocateable object code for sum() Relocateable object code for main() arith.o two_plus_one.o 71

72 Linking.o files to create executable gcc actually runs a program named ld to create the executable. Relocateable object code for sum() two_plus_one.o Relocateable object code for sum() arith.o gcc o two_plus_one two_plus_one.o arith.o Executable Program two_plus_one 72

73 Linking.o files to create executable Relocateable object code for sum() two_plus_one.o The executable contains all the code, with references resolved. It is ready to be invoked using the exec_() family of system calls. Relocateable object code for sum() arith.o gcc o two_plus one two_plus_one.o arith.o Executable Program two_plus_one 73

74 Linking.o files to create executable Relocateable object code for sum() two_plus_one.o The default name for an executable is a.out so programmers sometimes informally refer to any executable as an a.out. Relocateable object code for sum() arith.o gcc o two_plus_one two_plus_one.o arith.o Executable Program two_plus_one 74

75 Today How processes are created, managed and terminated Sharing the computer (redux) From file.c to a.out to running image Library routines and shared libraries 75

76 Routines like printf live in libraries. Ooops! Where does printf come from? Relocateable object code for sum() two_plus_one.o Relocateable object code for sum() arith.o gcc o two_plus one two_plus_one.o arith.o Executable Program two_plus_one 76

77 Ooops! Where does printf come from? Relocateable object code for sum() two_plus_one.o Routines like printf live in libraries. These are created with the ar command, which packages up several.o files together into a.a archive or library. You can list the.a along with your separate.o files and ld will pull from it any.o files it needs. Relocateable object code for sum() arith.o gcc o two_plus one two_plus_one.o arith.o Executable Program two_plus_one 77

78 Ooops! Where does printf come from? Relocateable object code for sum() two_plus_one.o Routines like printf live in libraries. These are created with the ar command, which packages up several.o files together into a.a archive or library. You can list the.a along with your separate.o files and ld will pull from it any.o files it needs. Executable Program two_plus_one Relocateable object code for sum() printf used to live in the system library named gcc o two_plus one two_plus_one.o arith.o libc.a, which the compiler links automatically into the executable (so you don t have to list it). arith.o 78

79 Why shared libraries? Problem: if printf is linked from the libc.a, then we get a separate copy in each program that uses printf Idea: what if we could have one copy and use memory mapping to put it into every executable that needs it? Challenges: We can t link it when ld builds the rest of the executable: we can just note we need it The same copy is likely to be mapped at different addresses in different programs 79

80 Why shared libraries? Problem: if printf is linked from the libc.a, then we get a separate copy in each program it s built that uses in to printf the system Idea: what if we could have one copy and use memory mapping to put it into every executable that needs it? Challenges: We ll use printf as an example even though Compile the source with fpic to make a position-independent.o file. We can t link it when ld builds the rest of the executable: we can just note we need it The same copy is likely to be mapped at different addresses in different programs Solution: compiler, linker and OS work together to support shared libraries gcc fpic printf.c generates position-independent code that can load at any address gcc shared o libc.so printf.o xxx.o obj3.o creates shared library gcc o two_plus_one two_plus_one.o arith.o libc.so 80

81 Why shared libraries? Problem: if printf is linked from the libc.a, then we get a separate copy in each program Link that uses printf.o and any other files with Idea: what if we could have one copy and use memory mapping to put it into every executable (.so) that file. needs it? Challenges: the shared option to create a shared library We can t link it when ld builds the rest of the executable: we can just note we need it The same copy is likely to be mapped at different addresses in different programs Solution: compiler, linker and OS work together to support shared libraries gcc fpic printf.c generates position-independent code that can load at any address gcc shared o libc.so printf.o xxx.o obj3.o creates shared library gcc o two_plus_one two_plus_one.o arith.o libc.so 81

82 Why shared libraries? Problem: if printf is linked from the libc.a, then we get a separate copy in each program that uses printf Idea: what if we could have one copy and use memory mapping to put it into every executable that needs it? Challenges: The linker recognizes.so files instead of including the code, it leaves a little stub that tells the OS to find and map the shared copy of the.so file when exec loads the program. (Actually, libc.so is so widely used that it s automatically linked, so you don t need to list it as you would your own.so libraries). We can t link it when ld builds the rest of the executable: we can just note we need it The same copy is likely to be mapped at different addresses in different programs Solution: compiler, linker and OS work together to support shared libraries gcc fpic printf.c generates position-independent code that can load at any address gcc shared o libc.so printf.o xxx.o obj3.o creates shared library gcc o two_plus_one two_plus_one.o arith.o libc.so 82

83 Memory mapping allows sharing of.so libraries CPU MAIN MEMORY OPERATING SYSTEM Play Video Angry Birds Angry Birds Browser argv, environ Stack (Browser Call Stack) Heap (malloc d) libc.so Static uninitialized (Browser Data) Static initialized (Browser Data) Text (Browser code) libc.so (with printf code) shows up at different locations in the two programs argv, environ Stack Call Stack) Heap (malloc d) libc.so??? Static uninitialized Data) Static initialized Data) Text code)

84 Memory mapping allows sharing of.so libraries CPU MAIN MEMORY OPERATING SYSTEM Play Video Angry Birds Angry Birds Browser argv, environ Stack Call Stack) Heap (malloc d) libc.so Static uninitialized (Browser Data) Static initialized (Browser Data) Text (Browser code) Only one copy lives in memory everyone shares it! libc.so argv, environ Stack Call Stack) Heap (malloc d) libc.so??? Static uninitialized Data) Static initialized Data) Text code)

85 Memory mapping allows sharing of.so libraries CPU MAIN MEMORY OPERATING SYSTEM Play Video Angry Birds Angry Birds Browser argv, environ Stack Call Stack) Heap (malloc d) libc.so Static uninitialized (Browser Data) Static initialized (Browser Data) Text (Browser code) Memory mapping hardware can do this Code must be positionindependent! libc.so argv, environ Stack Call Stack) Heap (malloc d) libc.so??? Static uninitialized Data) Static initialized Data) Text code)

86 Wrapup 86

87 Summary of today s topics Processes are cloned using fork To run a new program: fork then exec Kernel-to-program communication: A process calls the kernel using a system call (trap) The kernel calls a process using a signal Processes form a tree, and dead processes must be reaped The OS scheduler chooses high priority processes to run Process memory can be swapped or paged to disk when memory is tight Memory mapping & copy-on-write are used: To make fork quick To save memory by sharing executables and shared libraries across processes 87

88 Thank you! 88

Kernels & Processes The Structure of the Operating System

Kernels & Processes The Structure of the Operating System COMP 111: Operating Systems (Fall 2013) Kernels & Processes The Structure of the Operating System Noah Mendelsohn Tufts University Email: noah@cs.tufts.edu Web: http://www.cs.tufts.edu/~noah Based on a

More information

Process life and death. Tuesday, September 28, 2010

Process life and death. Tuesday, September 28, 2010 The_Visible_OS Page 1 Process life and death Tuesday, September 28, 2010 3:50 PM So far, We've studied what a process is, and know that it has a limited view of the OS, and has one of a limited number

More information

Lecture 4: Process Management

Lecture 4: Process Management Lecture 4: Process Management (Chapters 2-3) Process: execution context of running program. A process does not equal a program! Process is an instance of a program Many copies of same program can be running

More information

CPSC 341 OS & Networks. Processes. Dr. Yingwu Zhu

CPSC 341 OS & Networks. Processes. Dr. Yingwu Zhu CPSC 341 OS & Networks Processes Dr. Yingwu Zhu Process Concept Process a program in execution What is not a process? -- program on a disk A process is an active object, but a program is just a file It

More information

Operating System Structure

Operating System Structure Operating System Structure CSCI 4061 Introduction to Operating Systems Applications Instructor: Abhishek Chandra Operating System Hardware 2 Questions Operating System Structure How does the OS manage

More information

PROCESS CONTROL BLOCK TWO-STATE MODEL (CONT D)

PROCESS CONTROL BLOCK TWO-STATE MODEL (CONT D) MANAGEMENT OF APPLICATION EXECUTION PROCESS CONTROL BLOCK Resources (processor, I/O devices, etc.) are made available to multiple applications The processor in particular is switched among multiple applications

More information

CSci 4061 Introduction to Operating Systems. Processes in C/Unix

CSci 4061 Introduction to Operating Systems. Processes in C/Unix CSci 4061 Introduction to Operating Systems Processes in C/Unix Process as Abstraction Talked about C programs a bit Program is a static entity Process is an abstraction of a running program provided by

More information

OS lpr. www. nfsd gcc emacs ls 1/27/09. Process Management. CS 537 Lecture 3: Processes. Example OS in operation. Why Processes? Simplicity + Speed

OS lpr. www. nfsd gcc emacs ls 1/27/09. Process Management. CS 537 Lecture 3: Processes. Example OS in operation. Why Processes? Simplicity + Speed Process Management CS 537 Lecture 3: Processes Michael Swift This lecture begins a series of topics on processes, threads, and synchronization Today: processes and process management what are the OS units

More information

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2018 Lecture 20

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2018 Lecture 20 CS24: INTRODUCTION TO COMPUTING SYSTEMS Spring 2018 Lecture 20 LAST TIME: UNIX PROCESS MODEL Began covering the UNIX process model and API Information associated with each process: A PID (process ID) to

More information

Processes. CS439: Principles of Computer Systems January 24, 2018

Processes. CS439: Principles of Computer Systems January 24, 2018 Processes CS439: Principles of Computer Systems January 24, 2018 Last Time History Lesson Hardware expensive, humans cheap Hardware cheap, humans expensive Hardware very cheap, humans very expensive Dual-mode

More information

Unix Processes. What is a Process?

Unix Processes. What is a Process? Unix Processes Process -- program in execution shell spawns a process for each command and terminates it when the command completes Many processes all multiplexed to a single processor (or a small number

More information

Introduction to OS Processes in Unix, Linux, and Windows MOS 2.1 Mahmoud El-Gayyar

Introduction to OS Processes in Unix, Linux, and Windows MOS 2.1 Mahmoud El-Gayyar Introduction to OS Processes in Unix, Linux, and Windows MOS 2.1 Mahmoud El-Gayyar elgayyar@ci.suez.edu.eg Mahmoud El-Gayyar / Introduction to OS 1 Processes in Unix, Linux, and Windows Unix pre-empted

More information

Processes & Threads. (Chapter 3) CS 4410 Operating Systems. [R. Agarwal, L. Alvisi, A. Bracy, M. George, E. Sirer, R. Van Renesse]

Processes & Threads. (Chapter 3) CS 4410 Operating Systems. [R. Agarwal, L. Alvisi, A. Bracy, M. George, E. Sirer, R. Van Renesse] Processes & Threads (Chapter 3) CS 4410 Operating Systems [R. Agarwal, L. Alvisi, A. Bracy, M. George, E. Sirer, R. Van Renesse] Processes! 2 What is a Program? Program is a file containing: executable

More information

A process. the stack

A process. the stack A process Processes Johan Montelius What is a process?... a computation KTH 2017 a program i.e. a sequence of operations a set of data structures a set of registers means to interact with other processes

More information

OS lpr. www. nfsd gcc emacs ls 9/18/11. Process Management. CS 537 Lecture 4: Processes. The Process. Why Processes? Simplicity + Speed

OS lpr. www. nfsd gcc emacs ls 9/18/11. Process Management. CS 537 Lecture 4: Processes. The Process. Why Processes? Simplicity + Speed Process Management CS 537 Lecture 4: Processes Today: processes and process management what are the OS units of execution? how are they represented inside the OS? how is the CPU scheduled across processes?

More information

Processes. Johan Montelius KTH

Processes. Johan Montelius KTH Processes Johan Montelius KTH 2017 1 / 47 A process What is a process?... a computation a program i.e. a sequence of operations a set of data structures a set of registers means to interact with other

More information

Windows architecture. user. mode. Env. subsystems. Executive. Device drivers Kernel. kernel. mode HAL. Hardware. Process B. Process C.

Windows architecture. user. mode. Env. subsystems. Executive. Device drivers Kernel. kernel. mode HAL. Hardware. Process B. Process C. Structure Unix architecture users Functions of the System tools (shell, editors, compilers, ) standard library System call Standard library (printf, fork, ) OS kernel: processes, memory management, file

More information

PROCESSES. Jo, Heeseung

PROCESSES. Jo, Heeseung PROCESSES Jo, Heeseung TODAY'S TOPICS What is the process? How to implement processes? Inter-Process Communication (IPC) 2 WHAT IS THE PROCESS? Program? vs. Process? vs. Processor? 3 PROCESS CONCEPT (1)

More information

Processes. Jo, Heeseung

Processes. Jo, Heeseung Processes Jo, Heeseung Today's Topics What is the process? How to implement processes? Inter-Process Communication (IPC) 2 What Is The Process? Program? vs. Process? vs. Processor? 3 Process Concept (1)

More information

CSE 410: Computer Systems Spring Processes. John Zahorjan Allen Center 534

CSE 410: Computer Systems Spring Processes. John Zahorjan Allen Center 534 CSE 410: Computer Systems Spring 2018 Processes John Zahorjan zahorjan@cs.washington.edu Allen Center 534 1. What is a process? Processes 2. What's the process namespace? 3. How are processes represented

More information

IC221: Systems Programming 12-Week Written Exam [SOLUTIONS]

IC221: Systems Programming 12-Week Written Exam [SOLUTIONS] IC221: Systems Programming 12-Week Written Exam [SOLUTIONS] April 2, 2014 Answer the questions in the spaces provided on the question sheets. If you run out of room for an answer, continue on the back

More information

Process Control. Philipp Koehn. 23 April 2018

Process Control. Philipp Koehn. 23 April 2018 Process Control Philipp Koehn 23 April 2018 Control Flow 1 The CPU executes one instruction after another Typically, they are next to each other in memory (unless jumps, branches, and returns from subroutine)

More information

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2017 Lecture 19

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2017 Lecture 19 CS24: INTRODUCTION TO COMPUTING SYSTEMS Spring 2017 Lecture 19 LAST TIME Introduced UNIX signals A kernel facility that provides user-mode exceptional control flow Allows many hardware-level exceptions

More information

Processes. CS439: Principles of Computer Systems January 30, 2019

Processes. CS439: Principles of Computer Systems January 30, 2019 Processes CS439: Principles of Computer Systems January 30, 2019 What We Know Operating system complexity increased over time in response to economic and technological changes The three roles did not show

More information

CSE 451: Operating Systems Winter Module 4 Processes. Mark Zbikowski Allen Center 476

CSE 451: Operating Systems Winter Module 4 Processes. Mark Zbikowski Allen Center 476 CSE 451: Operating Systems Winter 2015 Module 4 Processes Mark Zbikowski mzbik@cs.washington.edu Allen Center 476 2013 Gribble, Lazowska, Levy, Zahorjan Process management This module begins a series of

More information

Process management. What s in a process? What is a process? The OS s process namespace. A process s address space (idealized)

Process management. What s in a process? What is a process? The OS s process namespace. A process s address space (idealized) Process management CSE 451: Operating Systems Spring 2012 Module 4 Processes Ed Lazowska lazowska@cs.washington.edu Allen Center 570 This module begins a series of topics on processes, threads, and synchronization

More information

Introduction to Processes

Introduction to Processes Computer Systems II Introduction to Processes 1 Review: Basic Computer Hardware CPU Instruction Register Control BUS read (disk) local buffer Disk Controller Memory Executable Disk 1 Review: Timing Problem

More information

Processes. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Processes. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University Processes Jin-Soo Kim (jinsookim@skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu OS Internals User space shell ls trap shell ps Kernel space File System Management I/O

More information

CS 355 Operating Systems. Keeping Track of Processes. When are processes created? Process States 1/26/18. Processes, Unix Processes and System Calls

CS 355 Operating Systems. Keeping Track of Processes. When are processes created? Process States 1/26/18. Processes, Unix Processes and System Calls CS 355 Operating Systems Processes, Unix Processes and System Calls Process User types command like run foo at keyboard I/O device driver for keyboard and screen Command is parsed by command shell Executable

More information

Computer Systems Assignment 2: Fork and Threads Package

Computer Systems Assignment 2: Fork and Threads Package Autumn Term 2018 Distributed Computing Computer Systems Assignment 2: Fork and Threads Package Assigned on: October 5, 2018 Due by: October 12, 2018 1 Understanding fork() and exec() Creating new processes

More information

Processes & Threads. Today. Next Time. ! Process concept! Process model! Implementing processes! Multiprocessing once again. ! More of the same J

Processes & Threads. Today. Next Time. ! Process concept! Process model! Implementing processes! Multiprocessing once again. ! More of the same J Processes & Threads Today! Process concept! Process model! Implementing processes! Multiprocessing once again Next Time! More of the same J The process model! Most computers can do more than one thing

More information

Getting to know you. Anatomy of a Process. Processes. Of Programs and Processes

Getting to know you. Anatomy of a Process. Processes. Of Programs and Processes Getting to know you Processes A process is an abstraction that supports running programs A sequential stream of execution in its own address space A process is NOT the same as a program! So, two parts

More information

ECE 550D Fundamentals of Computer Systems and Engineering. Fall 2017

ECE 550D Fundamentals of Computer Systems and Engineering. Fall 2017 ECE 550D Fundamentals of Computer Systems and Engineering Fall 2017 The Operating System (OS) Prof. John Board Duke University Slides are derived from work by Profs. Tyler Bletsch and Andrew Hilton (Duke)

More information

Chap 4, 5: Process. Dongkun Shin, SKKU

Chap 4, 5: Process. Dongkun Shin, SKKU Chap 4, 5: Process 1 Process Concept Job A bundle of program and data to be executed An entity before submission for execution Process (= running program) An entity that is registered to kernel for execution

More information

UNIX Processes. by Armin R. Mikler. 1: Introduction

UNIX Processes. by Armin R. Mikler. 1: Introduction UNIX Processes by Armin R. Mikler Overview The UNIX Process What is a Process Representing a process States of a process Creating and managing processes fork() wait() getpid() exit() etc. Files in UNIX

More information

www nfsd emacs lpr Process Management CS 537 Lecture 4: Processes Example OS in operation Why Processes? Simplicity + Speed

www nfsd emacs lpr Process Management CS 537 Lecture 4: Processes Example OS in operation Why Processes? Simplicity + Speed Process Management CS 537 Lecture 4: Processes Michael Swift This lecture begins a series of topics on processes, threads, and synchronization Today: processes and process management what are the OS units

More information

Processes & Signals. System Runs Many Processes Concurrently. State consists of memory image + register values + program counter

Processes & Signals. System Runs Many Processes Concurrently. State consists of memory image + register values + program counter Processes & Signals Topics Process Hierarchy Shells Signals The World of Multitasking System Runs Many Processes Concurrently Process: executing program State consists of memory image + register values

More information

PROCESS MANAGEMENT. Operating Systems 2015 Spring by Euiseong Seo

PROCESS MANAGEMENT. Operating Systems 2015 Spring by Euiseong Seo PROCESS MANAGEMENT Operating Systems 2015 Spring by Euiseong Seo Today s Topics Process Concept Process Scheduling Operations on Processes Interprocess Communication Examples of IPC Systems Communication

More information

Processes. CS3026 Operating Systems Lecture 05

Processes. CS3026 Operating Systems Lecture 05 Processes CS3026 Operating Systems Lecture 05 Dispatcher Admit Ready Queue Dispatch Processor Release Timeout or Yield Event Occurs Blocked Queue Event Wait Implementation: Using one Ready and one Blocked

More information

Altering the Control Flow

Altering the Control Flow Altering the Control Flow Up to Now: two mechanisms for changing control flow: Jumps and branches Call and return using the stack discipline. Both react to changes in program state. Insufficient for a

More information

CSC 1600 Unix Processes. Goals of This Lecture

CSC 1600 Unix Processes. Goals of This Lecture CSC 1600 Unix Processes q Processes Goals of This Lecture q Process vs. program q Context switching q Creating a new process q fork: process creates a new child process q wait: parent waits for child process

More information

EXPERIMENT NO : M/C Lenovo Think center M700 Ci3,6100,6th Gen. H81, 4GB RAM,500GB HDD

EXPERIMENT NO : M/C Lenovo Think center M700 Ci3,6100,6th Gen. H81, 4GB RAM,500GB HDD GROUP - C EXPERIMENT NO : 12 1. Title: Implement UNIX system calls like ps, fork, join, exec family, and wait for process management (use shell script/ Java/ C programming) 2. Objectives : - To understand

More information

Introduction to Operating Systems Prof. Chester Rebeiro Department of Computer Science and Engineering Indian Institute of Technology, Madras

Introduction to Operating Systems Prof. Chester Rebeiro Department of Computer Science and Engineering Indian Institute of Technology, Madras Introduction to Operating Systems Prof. Chester Rebeiro Department of Computer Science and Engineering Indian Institute of Technology, Madras Week 03 Lecture 12 Create, Execute, and Exit from a Process

More information

CS213. Exceptional Control Flow Part II. Topics Process Hierarchy Signals

CS213. Exceptional Control Flow Part II. Topics Process Hierarchy Signals CS213 Exceptional Control Flow Part II Topics Process Hierarchy Signals ECF Exists at All Levels of a System Exceptions Hardware and operating system kernel software Concurrent processes Hardware timer

More information

Exceptional Control Flow Part I

Exceptional Control Flow Part I Exceptional Control Flow Part I Today! Exceptions! Process context switches! Creating and destroying processes Next time! Signals, non-local jumps, Fabián E. Bustamante, 2007 Control flow! Computers do

More information

Unix-Linux 2. Unix is supposed to leave room in the process table for a superuser process that could be used to kill errant processes.

Unix-Linux 2. Unix is supposed to leave room in the process table for a superuser process that could be used to kill errant processes. Unix-Linux 2 fork( ) system call is successful parent suspended child created fork( ) returns child pid to parent fork( ) returns zero value to child; zero is the pid of the swapper/scheduler process both

More information

Introduction to Operating Systems Prof. Chester Rebeiro Department of Computer Science and Engineering Indian Institute of Technology, Madras

Introduction to Operating Systems Prof. Chester Rebeiro Department of Computer Science and Engineering Indian Institute of Technology, Madras Introduction to Operating Systems Prof. Chester Rebeiro Department of Computer Science and Engineering Indian Institute of Technology, Madras Week - 01 Lecture - 03 From Programs to Processes Hello. In

More information

Processes. Dr. Yingwu Zhu

Processes. Dr. Yingwu Zhu Processes Dr. Yingwu Zhu Process Growing Memory Stack expands automatically Data area (heap) can grow via a system call that requests more memory - malloc() in c/c++ Entering the kernel (mode) Hardware

More information

Interrupts, Fork, I/O Basics

Interrupts, Fork, I/O Basics Interrupts, Fork, I/O Basics 12 November 2017 Lecture 4 Slides adapted from John Kubiatowicz (UC Berkeley) 12 Nov 2017 SE 317: Operating Systems 1 Topics for Today Interrupts Native control of Process

More information

CSC209 Fall Karen Reid 1

CSC209 Fall Karen Reid 1 ' & ) ) #$ "! How user programs interact with the Operating System. Somehow we need to convert a program into machine code (object code). A compiler passes over a whole program before translating it into

More information

The Process Abstraction. CMPU 334 Operating Systems Jason Waterman

The Process Abstraction. CMPU 334 Operating Systems Jason Waterman The Process Abstraction CMPU 334 Operating Systems Jason Waterman How to Provide the Illusion of Many CPUs? Goal: run N processes at once even though there are M CPUs N >> M CPU virtualizing The OS can

More information

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2018 Lecture 18

CS24: INTRODUCTION TO COMPUTING SYSTEMS. Spring 2018 Lecture 18 CS24: INTRODUCTION TO COMPUTING SYSTEMS Spring 2018 Lecture 18 LAST TIME: OVERVIEW Expanded on our process abstraction A special control process manages all other processes Uses the same process abstraction

More information

CS 550 Operating Systems Spring Process II

CS 550 Operating Systems Spring Process II CS 550 Operating Systems Spring 2018 Process II 1 Recap: Process Informal definition: A process is a program in execution. Process is not the same as a program. Program is a passive entity stored in the

More information

Operating Systems and Networks Assignment 9

Operating Systems and Networks Assignment 9 Spring Term 01 Operating Systems and Networks Assignment 9 Assigned on: rd May 01 Due by: 10th May 01 1 General Operating Systems Questions a) What is the purpose of having a kernel? Answer: A kernel is

More information

What is a Process. Processes. Programs and Processes. System Classification 3/5/2013. Process: An execution stream and its associated state

What is a Process. Processes. Programs and Processes. System Classification 3/5/2013. Process: An execution stream and its associated state What is a Process Process: An execution stream and its associated state Processes Execution Stream Set of instructions Thread of control Process State Hardware state Privilege level, segments, page tables

More information

Week 2 Intro to the Shell with Fork, Exec, Wait. Sarah Diesburg Operating Systems CS 3430

Week 2 Intro to the Shell with Fork, Exec, Wait. Sarah Diesburg Operating Systems CS 3430 Week 2 Intro to the Shell with Fork, Exec, Wait Sarah Diesburg Operating Systems CS 3430 1 Why is the Shell Important? Shells provide us with a way to interact with the core system Executes programs on

More information

CSE 153 Design of Operating Systems Fall 2018

CSE 153 Design of Operating Systems Fall 2018 CSE 153 Design of Operating Systems Fall 2018 Lecture 4: Processes (2) Threads Process Creation: Unix In Unix, processes are created using fork() int fork() fork() Creates and initializes a new PCB Creates

More information

Signals. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University

Signals. Jin-Soo Kim Computer Systems Laboratory Sungkyunkwan University Signals Jin-Soo Kim (jinsookim@skku.edu) Computer Systems Laboratory Sungkyunkwan University http://csl.skku.edu Multitasking (1) Programmer s model of multitasking fork() spawns new process Called once,

More information

Altering the Control Flow

Altering the Control Flow Altering the Control Flow Up to Now: two mechanisms for changing control flow: Jumps and branches Call and return using the stack discipline. Both react to changes in program state. Insufficient for a

More information

Killing Zombies, Working, Sleeping, and Spawning Children

Killing Zombies, Working, Sleeping, and Spawning Children Killing Zombies, Working, Sleeping, and Spawning Children CS 333 Prof. Karavanic (c) 2015 Karen L. Karavanic 1 The Process Model The OS loads program code and starts each job. Then it cleans up afterwards,

More information

Mon Sep 17, 2007 Lecture 3: Process Management

Mon Sep 17, 2007 Lecture 3: Process Management Mon Sep 17, 2007 Lecture 3: Process Management September 19, 2007 1 Review OS mediates between hardware and user software QUIZ: Q: Name three layers of a computer system where the OS is one of these layers.

More information

Control Flow. Systemprogrammering 2007 Föreläsning 2 Exceptional Control Flow Part I. Exceptional Control Flow. Altering the Control Flow

Control Flow. Systemprogrammering 2007 Föreläsning 2 Exceptional Control Flow Part I. Exceptional Control Flow. Altering the Control Flow Systemprogrammering 2007 Föreläsning 2 Exceptional Control Flow Part I Topics Exceptions Process context switches Creating and destroying processes Control Flow Computers do Only One Thing From startup

More information

Reading Assignment 4. n Chapter 4 Threads, due 2/7. 1/31/13 CSE325 - Processes 1

Reading Assignment 4. n Chapter 4 Threads, due 2/7. 1/31/13 CSE325 - Processes 1 Reading Assignment 4 Chapter 4 Threads, due 2/7 1/31/13 CSE325 - Processes 1 What s Next? 1. Process Concept 2. Process Manager Responsibilities 3. Operations on Processes 4. Process Scheduling 5. Cooperating

More information

Operating systems and concurrency - B03

Operating systems and concurrency - B03 Operating systems and concurrency - B03 David Kendall Northumbria University David Kendall (Northumbria University) Operating systems and concurrency - B03 1 / 15 Introduction This lecture gives a more

More information

Exceptional Control Flow Part I Oct. 17, 2002

Exceptional Control Flow Part I Oct. 17, 2002 15-213 The course that gives CMU its Zip! Exceptional Control Flow Part I Oct. 17, 2002 Topics Exceptions Process context switches Creating and destroying processes class16.ppt Control Flow Computers do

More information

Announcement. Exercise #2 will be out today. Due date is next Monday

Announcement. Exercise #2 will be out today. Due date is next Monday Announcement Exercise #2 will be out today Due date is next Monday Major OS Developments 2 Evolution of Operating Systems Generations include: Serial Processing Simple Batch Systems Multiprogrammed Batch

More information

CSci 4061 Introduction to Operating Systems. IPC: Basics, Pipes

CSci 4061 Introduction to Operating Systems. IPC: Basics, Pipes CSci 4061 Introduction to Operating Systems IPC: Basics, Pipes Today Directory wrap-up Communication/IPC Test in one week Communication Abstraction: conduit for data exchange between two or more processes

More information

Operating Systems. Lecture 05

Operating Systems. Lecture 05 Operating Systems Lecture 05 http://web.uettaxila.edu.pk/cms/sp2013/seosbs/ February 25, 2013 Process Scheduling, System Calls Execution (Fork,Wait,Exit,Exec), Inter- Process Communication Schedulers Long

More information

SE350: Operating Systems

SE350: Operating Systems SE350: Operating Systems Tutorial: The Programming Interface Main Points Creating and managing processes fork, exec, wait Example: implementing a shell Shell A shell is a job control system Allows programmer

More information

518 Lecture Notes Week 3

518 Lecture Notes Week 3 518 Lecture Notes Week 3 (Sept. 15, 2014) 1/8 518 Lecture Notes Week 3 1 Topics Process management Process creation with fork() Overlaying an existing process with exec Notes on Lab 3 2 Process management

More information

CS 201. Processes. Gerson Robboy Portland State University

CS 201. Processes. Gerson Robboy Portland State University CS 201 Processes Gerson Robboy Portland State University Review Definition: A process is an instance of a running program. One of the most fundamental concepts in computer science. Not the same as program

More information

Operating Systemss and Multicore Programming (1DT089)

Operating Systemss and Multicore Programming (1DT089) Operating Systemss and Multicore Programming (1DT089) Problem Set 1 - Tutorial January 2013 Uppsala University karl.marklund@it.uu.se pointers.c Programming with pointers The init() functions is similar

More information

CS 33. Architecture and the OS. CS33 Intro to Computer Systems XIX 1 Copyright 2018 Thomas W. Doeppner. All rights reserved.

CS 33. Architecture and the OS. CS33 Intro to Computer Systems XIX 1 Copyright 2018 Thomas W. Doeppner. All rights reserved. CS 33 Architecture and the OS CS33 Intro to Computer Systems XIX 1 Copyright 2018 Thomas W. Doeppner. All rights reserved. The Operating System My Program Mary s Program Bob s Program OS CS33 Intro to

More information

Fall 2015 COMP Operating Systems. Lab #3

Fall 2015 COMP Operating Systems. Lab #3 Fall 2015 COMP 3511 Operating Systems Lab #3 Outline n Operating System Debugging, Generation and System Boot n Review Questions n Process Control n UNIX fork() and Examples on fork() n exec family: execute

More information

628 Lecture Notes Week 4

628 Lecture Notes Week 4 628 Lecture Notes Week 4 (February 3, 2016) 1/8 628 Lecture Notes Week 4 1 Topics I/O Redirection Notes on Lab 4 Introduction to Threads Review Memory spaces #include #include int

More information

CSCE Operating Systems Interrupts, Exceptions, and Signals. Qiang Zeng, Ph.D. Fall 2018

CSCE Operating Systems Interrupts, Exceptions, and Signals. Qiang Zeng, Ph.D. Fall 2018 CSCE 311 - Operating Systems Interrupts, Exceptions, and Signals Qiang Zeng, Ph.D. Fall 2018 Previous Class Process state transition Ready, blocked, running Call Stack Execution Context Process switch

More information

API Interlude: Process Creation (DRAFT)

API Interlude: Process Creation (DRAFT) 5 API Interlude: Process Creation (DRAFT) In this interlude, we discuss process creation in UNIX systems. UNIX presents one of the most intriguing ways to create a new process with a pair of system calls:

More information

University of Washington What is a process?

University of Washington What is a process? What is a process? What is a program? A processor? A process? 1 What is a process? Why are we learning about processes? Processes are another abstrac'on in our computer system the process abstrac9on provides

More information

Are branches/calls the only way we can get the processor to go somewhere in a program? What is a program? A processor? A process?

Are branches/calls the only way we can get the processor to go somewhere in a program? What is a program? A processor? A process? Processes and control flow Are branches/calls the only way we can get the processor to go somewhere in a program? What is a program? A processor? A process? 1 Control Flow Processors do only one thing:

More information

Most of the work is done in the context of the process rather than handled separately by the kernel

Most of the work is done in the context of the process rather than handled separately by the kernel Process Control Process Abstraction for a running program Manages program s use of memory, cpu time, and i/o resources Most of the work is done in the context of the process rather than handled separately

More information

CS 537 Lecture 2 - Processes

CS 537 Lecture 2 - Processes CS 537 Lecture 2 - Processes Michael Swift 1 Basic Structure Kernel is a big program that starts when you boot your program Has full access to physical hardware. User programs, utilities, services see

More information

W4118 Operating Systems. Junfeng Yang

W4118 Operating Systems. Junfeng Yang W4118 Operating Systems Junfeng Yang What is a process? Outline Process dispatching Common process operations Inter-process Communication What is a process Program in execution virtual CPU Process: an

More information

CSE 380 Computer Operating Systems. Instructor: Insup Lee. University of Pennsylvania Fall 2003

CSE 380 Computer Operating Systems. Instructor: Insup Lee. University of Pennsylvania Fall 2003 CSE 380 Computer Operating Systems Instructor: Insup Lee University of Pennsylvania Fall 2003 Lecture Note 2: Processes and Threads Lecture Note 2.1: Processes and System Calls 1 Process q Consider a simple

More information

CS 33. Architecture and the OS. CS33 Intro to Computer Systems XIX 1 Copyright 2017 Thomas W. Doeppner. All rights reserved.

CS 33. Architecture and the OS. CS33 Intro to Computer Systems XIX 1 Copyright 2017 Thomas W. Doeppner. All rights reserved. CS 33 Architecture and the OS CS33 Intro to Computer Systems XIX 1 Copyright 2017 Thomas W. Doeppner. All rights reserved. The Operating System My Program Mary s Program Bob s Program OS CS33 Intro to

More information

CS240: Programming in C

CS240: Programming in C CS240: Programming in C Lecture 17: Processes, Pipes, and Signals Cristina Nita-Rotaru Lecture 17/ Fall 2013 1 Processes in UNIX UNIX identifies processes via a unique Process ID Each process also knows

More information

Princeton University. Computer Science 217: Introduction to Programming Systems. Process Management

Princeton University. Computer Science 217: Introduction to Programming Systems. Process Management Princeton University Computer Science 217: Introduction to Programming Systems Process Management 1 Goals of this Lecture Help you learn about: Creating new processes Waiting for processes to terminate

More information

Processes and Threads. Processes and Threads. Processes (2) Processes (1)

Processes and Threads. Processes and Threads. Processes (2) Processes (1) Processes and Threads (Topic 2-1) 2 홍성수 Processes and Threads Question: What is a process and why is it useful? Why? With many things happening at once in a system, need some way of separating them all

More information

Processes: Introduction. CS 241 February 13, 2012

Processes: Introduction. CS 241 February 13, 2012 Processes: Introduction CS 241 February 13, 2012 1 Announcements MP2 due tomorrow Deadline and contest cutoff 11:59 p.m. Fabulous prizes on Wednesday MP3 out Wednesday: Shell (1 week) Code from this lecture

More information

System Programming. Introduction to Unix

System Programming. Introduction to Unix Content : by Dr. B. Boufama School of Computer Science University of Windsor Instructor: Dr. A. Habed adlane@cs.uwindsor.ca http://cs.uwindsor.ca/ adlane/60-256 Content Content 1 Introduction 2 3 Introduction

More information

CSC 252: Computer Organization Spring 2018: Lecture 19

CSC 252: Computer Organization Spring 2018: Lecture 19 CSC 252: Computer Organization Spring 2018: Lecture 19 Instructor: Yuhao Zhu Department of Computer Science University of Rochester Action Items: Programming Assignment 3 grades are out Programming Assignment

More information

Princeton University Computer Science 217: Introduction to Programming Systems. Process Management

Princeton University Computer Science 217: Introduction to Programming Systems. Process Management Princeton University Computer Science 217: Introduction to Programming Systems Process Management 1 Goals of this Lecture Help you learn about: Creating new processes Waiting for processes to terminate

More information

Mid Term from Feb-2005 to Nov 2012 CS604- Operating System

Mid Term from Feb-2005 to Nov 2012 CS604- Operating System Mid Term from Feb-2005 to Nov 2012 CS604- Operating System Latest Solved from Mid term Papers Resource Person Hina 1-The problem with priority scheduling algorithm is. Deadlock Starvation (Page# 84) Aging

More information

Shell and Signals. Computer Organization 3/17/2015. CSC252 - Spring The World of Multiprogramming or Multitasking. Unix Process Hierarchy

Shell and Signals. Computer Organization 3/17/2015. CSC252 - Spring The World of Multiprogramming or Multitasking. Unix Process Hierarchy Shell and Signals Kai Shen The World of Multiprogramming or Multitasking System runs many processes concurrently Process: executing program State includes memory image + register values + program counter

More information

Processes. Today. Next Time. ! Process concept! Process model! Implementing processes! Multiprocessing once again. ! Scheduling processes

Processes. Today. Next Time. ! Process concept! Process model! Implementing processes! Multiprocessing once again. ! Scheduling processes Processes Today! Process concept! Process model! Implementing processes! Multiprocessing once again Next Time! Scheduling processes The process model! Most computers can do more than one thing at a time

More information

CS 322 Operating Systems Practice Midterm Questions

CS 322 Operating Systems Practice Midterm Questions ! CS 322 Operating Systems 1. Processes go through the following states in their lifetime. time slice ends Consider the following events and answer the questions that follow. Assume there are 5 processes,

More information

CS 471 Operating Systems. Yue Cheng. George Mason University Fall 2017

CS 471 Operating Systems. Yue Cheng. George Mason University Fall 2017 CS 471 Operating Systems Yue Cheng George Mason University Fall 2017 Outline o Process concept o Process creation o Process states and scheduling o Preemption and context switch o Inter-process communication

More information

Giving credit where credit is due

Giving credit where credit is due CSCE 230J Computer Organization Exceptional Control Flow Part I Dr. Steve Goddard goddard@cse.unl.edu http://cse.unl.edu/~goddard/courses/csce230j Giving credit where credit is due Most of slides for this

More information

Exceptional Control Flow: Exceptions and Processes

Exceptional Control Flow: Exceptions and Processes Exceptional Control Flow: Exceptions and Processes 15-213 / 18-213: Introduction to Computer Systems 12 th Lecture, June 18, 2013 Instructors: Greg Kesden 1 Today Exceptional Control Flow Processes 2 Control

More information

Exceptional Control Flow Part I September 22, 2008

Exceptional Control Flow Part I September 22, 2008 15-213 Exceptional Control Flow Part I September 22, 2008 Topics Exceptions Process context switches Creating and destroying processes class11.ppt Control Flow Computers do only one thing: From startup

More information

Roadmap. Tevfik Ko!ar. CSC Operating Systems Fall Lecture - III Processes. Louisiana State University. Processes. September 1 st, 2009

Roadmap. Tevfik Ko!ar. CSC Operating Systems Fall Lecture - III Processes. Louisiana State University. Processes. September 1 st, 2009 CSC 4103 - Operating Systems Fall 2009 Lecture - III Processes Tevfik Ko!ar Louisiana State University September 1 st, 2009 1 Roadmap Processes Basic Concepts Process Creation Process Termination Context

More information