Today’s Topics Introducing process: the basic mechanism for concurrent programming –Process management related system calls Process creation Process termination.

Slides:



Advertisements
Similar presentations
Process Management.
Advertisements

1 CS345 Operating Systems Φροντιστήριο Άσκησης 1.
15-213/ Intro to Computer Systems by btan with reference to Spring 10’s slides.
Process Control Hua LiSystems ProgrammingCS2690Process Control Page 1 of 41.
1 Processes Professor Jennifer Rexford
1 Processes and Pipes COS 217 Professor Jennifer Rexford.
Processes CSCI 444/544 Operating Systems Fall 2008.
CS 311 – Lecture 14 Outline Process management system calls Introduction System calls  fork()  getpid()  getppid()  wait()  exit() Orphan process.
1 Processes and Pipes. 2 "He was below me. I saw his markings, manoeuvred myself behind him and shot him down. If I had known it was Saint-Exupery, I.
Process Control in Unix Operating Systems Hebrew University Spring 2004.
Process in Unix, Linux and Windows CS-3013 C-term Processes in Unix, Linux, and Windows CS-3013 Operating Systems (Slides include materials from.
CS-502 Fall 2006Processes in Unix, Linux, & Windows 1 Processes in Unix, Linux, and Windows CS502 Operating Systems.
CSSE Operating Systems
Unix & Windows Processes 1 CS502 Spring 2006 Unix/Windows Processes.
Fork and Exec Unix Model Tutorial 3. Process Management Model The Unix process management model is split into two distinct operations : 1. The creation.
Processes in Unix, Linux, and Windows CS-502 Fall Processes in Unix, Linux, and Windows CS502 Operating Systems (Slides include materials from Operating.
March 1, 2002Serguei A. Mokhov, 1 Brief Introduction to System Calls and Process Management COMP 229, 346, 444, 5201 Revision 1.3.
Process. Process Concept Process – a program in execution Textbook uses the terms job and process almost interchangeably A process includes: – program.
Process Control. Major Requirements of an Operating System Interleave the execution of several processes to maximize processor utilization while providing.
Lecture Topics: 11/3 Address spaces Memory protection Creating a process –NT style –Unix style.
Copyright ©: Nahrstedt, Angrave, Abdelzaher1 Processes Tarek Abdelzaher Vikram Adve.
Process in Unix, Linux, and Windows CS-3013 A-term Processes in Unix, Linux, and Windows CS-3013 Operating Systems (Slides include materials from.
Introduction to Processes CS Intoduction to Operating Systems.
March 1, 2002Serguei A. Mokhov, 1 Brief Introduction to System Calls and Process Management COMP229 - System Software Edition 1.1,
Lecture 5 Process, Thread and Task September 22, 2015 Kyu Ho Park.
Processes and Threads CS550 Operating Systems. Processes and Threads These exist only at execution time They have fast state changes -> in memory and.
1 Week 2 The Crunchy Shell to the Soft and Chewy Kernel… Sarah Diesburg 8/3/2010 COP4610 / CGS5765.
Lecture 3 Process Concepts. What is a Process? A process is the dynamic execution context of an executing program. Several processes may run concurrently,
Creating and Executing Processes
CE Operating Systems Lecture 10 Processes and process management in Linux.
System calls for Process management
Scis.regis.edu ● CS 468: Advanced UNIX Class 5 Dr. Jesús Borrego Regis University 1.
CS 153 Design of Operating Systems Spring 2015 Lecture 5: Processes and Threads.
Process Management CS3320 Spring Process A process is an instance of a running program. –Not the same as “program” or “processor” Process provides.
Operating Systems Process Creation
CS4315A. Berrached:CMS:UHD1 Process Management Chapter 6.
What is a Process? u A process is an executable “cradle” in which a program may run u This “cradle” provides an environment in which the program can run,
Operating System Concepts and Techniques Lecture 3 Process M. Naghibzadeh Reference M. Naghibzadeh, Operating System Concepts and Techniques, First ed.,
Operating Systems ECE344 Ashvin Goel ECE University of Toronto Unix System Calls and Posix Threads.
CSCI 330 UNIX and Network Programming Unit XII: Process & Pipe Part 1.
Process Management Azzam Mourad COEN 346.
Concurrent Servers. Idea Behind Concurrent Servers Server Client 1 Server 1 X.
Tutorial 3. In this tutorial we’ll see Fork() and Exec() system calls.
System calls for Process management Process creation, termination, waiting.
CS241 Systems Programming Discussion Section Week 2 Original slides by: Stephen Kloder.
1 Unix system calls fork( ) wait( ) exit( ). 2 How To Create New Processes? n Underlying mechanism -A process runs fork to create a child process -Parent.
CS241 Systems Programming Discussion Section Week 2 Original slides by: Stephen Kloder.
S ALVATORE DI G IROLAMO (TA) Networks and Operating Systems: Exercise Session 1.
A process is a program in execution A running system consists of multiple processes – OS processes Processes started by the OS to do “system things” –
Section 8: Processes What is a process Creating processes Fork-Exec
Protection of System Resources
Using Processes.
Unix Process Management
Processes in Unix, Linux, and Windows
UNIX PROCESSES.
Processes in Unix, Linux, and Windows
Lecture 5: Process Creation
Fork and Exec Unix Model
Processes in Unix, Linux, and Windows
Tutorial 3 Tutorial 3.
Process Programming Interface
CS 105 “Tour of the Black Holes of Computing!”
Processes Prof. Ikjun Yeom TA – Mugyo
CS 105 “Tour of the Black Holes of Computing!”
CS 105 “Tour of the Black Holes of Computing!”
Lecture 6: Multiprogramming and Context Switching
Processes in Unix, Linux, and Windows
Processes in Unix and Windows
CS510 Operating System Foundations
Presentation transcript:

Today’s Topics Introducing process: the basic mechanism for concurrent programming –Process management related system calls Process creation Process termination Running another program in a process Synchronization between Parent/child processes

Computer systems Overview User Space OS CPU scheduling Memory Mgmt File system Device Mgmt Processes Network Stack System Call Interface HW CPUMemory Disk Keyboard Monitor

Computer systems user’s view Program1 Each program owns its own (virtual) computer. The execution of a program does not affect one another. CPU Memory Disk Keyboard Monitor Program2 CPU Memory Disk Keyboard Monitor ProgramX CPU Memory Disk Keyboard Monitor

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 disk –Program (code) is just one part of the process.

What else in a process? Process context – everything needed to run resume execution of a program: –Memory space (static, dynamic) –Procedure call stack –Open files, connections –Registers and counters : Program counter, Stack pointer, General purpose registers –……

Why process? Multiple processes (users) share the system resources. Multiple processes run independently Which of the following is more important? –Process isolation (the illusion that each process is the only one on the machine). –Process interaction (synchronization, inter-process communication).

Examining Processes in Unix ps command –Standard process attributes /proc directory –More interesting information. –Try “man proc” Top, vmstat command –Examining CPU and memory usage statistics.

Creating a New Process - fork() pid = fork(); if (pid == -1) { fprintf(stderr, "fork failed\n"); exit(1); } if (pid == 0) { printf(“This is the child\n"); exit(0); } if (pid > 0) { printf(“This is parent. The child is %d\n", pid); exit(0); }

Points to Note fork() is called once … … but it returns twice!! –Once in the parent and –Once in the child –See example1.c Fork() basically duplicates the parent process image –Both processes are exactly the same after the fork() call. Are there any dependence between the two processes? –Provide a way to distinguish the parent and the child.

Points to Note How to distinguish parent and child?? –Return value in child = 0 –Return value in parent = process id of child –See example2.c What about the data in the program? –See example6.c. Return value of -1 indicates error in all UNIX system calls – another UNIX convention Is it true: All processes are created by fork() in UNIX?

Running an existing command in a program – exec() int execl(char * pathname, char * arg0, …, (char *)0); int execv(char * pathname, char * argv[]); int execle(char * pathname, char * arg0, …, (char *)0, char envp[]); int execve(char * pathname, char * argv[], char envp[]); int execlp(char * filename, char * arg0, …, (char *)0); int execvp(char * filename, char * argv[]);

execv int execv(char * pathname, char * argv[]); Example: to run “/bin/ls –l –a /” pathname: file path for the executable char *argv[]: must be exactly the same as the C/C++ command line argument. E.g argv[4] must be NULL. See example3d.c

Examples Running one command example3a.c –Run command with any parameters? Run all commands in the comand line argument – example3b.c?

Properties of exec() Replaces current process image with new program image. –E.g. parent image replaced by the new program image. –If successful, everything after the exec() call will NOT be executed. Will execv() return anything other than -1?

Running a command without killing the process

Parent

Running a command without killing the process? Parent Child Fork(…)

Running a command without killing the process, see example3.c, fixing example3b.c Parent Child Fork(…) Exec(…) New program image in execution

Terminating a process exit (int status) –Clean up the process (e.g close all files) –Tell its parent processes that he is dying (SIGCHLD) –Tell child processes that he is dying (SIGHUP) –Exit status can be accessed by the parent process. When a process exits – not all resources associated with the process are freed yet!! –ps can still see the process ( ), see example6.c

Parent/child synchronization Parent created the child, he has the responsibility to see it through: –check if the child is done. wait, waitpid –This will clean up all trace of the child process from the system. See example6.c –check if the exit status of the child pid_t wait(int *stat_loc), see example4.c –Some others such as whether the child was killed by an signal. etc A child has no responsibility for the parent

–Processes are identified by a process id (pid) getpid(): find your own pid getppid(): find the pid of the parent –See example5.c for the time for system calls versus regular routine calls. –A question: How to implement the system routine?

Review Why processes? What is process context? How to check processes in UNIX? What does fork() do? What is its return value? Does fork() create all processes in a UNIX system? What does execv() do? What is its return value? How to run a command in a program without getting killed? Does exit completely clean up a process? Can a parent process tell if its child process terminate normally? Can a child process tell if its parent process terminate normally?