March 1, 2002Serguei A. Mokhov, 1 Brief Introduction to System Calls and Process Management COMP229 - System Software Edition 1.1,

Slides:



Advertisements
Similar presentations
1 CS345 Operating Systems Φροντιστήριο Άσκησης 1.
Advertisements

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.
UNIX Process Control Bach 7 Operating Systems Course Hebrew University Spring 2007.
Processes CSCI 444/544 Operating Systems Fall 2008.
Source: T.Y. Wong, Chinese University of Hong Kong Supplementary materials: Command shell using fork, exec, and wait.
Advanced OS Chapter 3p2 Sections 3.4 / 3.5. Interrupts These enable software to respond to signals from hardware. The set of instructions to be executed.
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.
Unix & Windows Processes 1 CS502 Spring 2006 Unix/Windows Processes.
CSE 451 Section 4 Project 2 Design Considerations.
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.
Shell (Part 1). Process r A process is an instance of an application running r If there are two instances of an application running then there are two.
Process in Unix, Linux, and Windows CS-3013 A-term Processes in Unix, Linux, and Windows CS-3013 Operating Systems (Slides include materials from.
Fundamentals CIS 552. Fundamentals Low-level I/O (read/write using system calls)  Opening/Creating files  Reading & Writing files  Moving around in.
Today’s Topics Introducing process: the basic mechanism for concurrent programming –Process management related system calls Process creation Process termination.
The process concept (section 3.1, 3.3 and demos)  Process: An entity capable of requesting and using computer resources (memory, CPU cycles, files, etc).
Exec Function calls Used to begin a processes execution. Accomplished by overwriting process imaged of caller with that of called. Several flavors, use.
CS162B: Forking Jacob T. Chan. Fork  Forks are:  Implement with two or more prongs that is used for taking up or digging  Division into branches or.
1 Logging in to a UNIX System init ( Process ID 1 created by the kernel at bootstrap ) spawns getty for every terminal device invokes our login shell terminal.
1 Week 2 The Crunchy Shell to the Soft and Chewy Kernel… Sarah Diesburg 8/3/2010 COP4610 / CGS5765.
System V IPC Provides three mechanisms for InterProcess Communication (IPC) : Messages : exchange messages with any process or server. Semaphores : allow.
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.
Concurrent Processes Processes can concurrently run same program. Processes can concurrently run same program. Processes can start other processes. Processes.
Operating Systems Process Creation
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,
CSCI 330 UNIX and Network Programming Unit XII: Process & Pipe Part 1.
Process Management Azzam Mourad COEN 346.
Project 2: User Programs Abdelmounaam Rezgui Acknowledgment: The content of some slides is partly taken from Josh Wiseman’s presentation.
Concurrent Servers. Idea Behind Concurrent Servers Server Client 1 Server 1 X.
1 A Seven-State Process Model. 2 CPU Switch From Process to Process Silberschatz, Galvin, and Gagne  1999.
CSCI 330 UNIX and Network Programming
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.
4.1 Operating Systems Lecture 9 Fork and Exec Read Ch
Process Related System Calls By Neha Hulkoti & Kavya Bhat.
1 Intro to the Shell with Fork, Exec, Wait Sarah Diesburg Operating Systems CS 3430.
June 20, 2002Serguei A. Mokhov, 1 Drivers, Interrupts, and Trap Explained COMP346/ Operating Systems Tutorial 3.5 Revision.
Process Manipulation. Process Manipulation in UNIX Basic process manipulation: creation, program loading, exiting, … fork(), exec(), wait(), exit() Process.
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” –
Process API COMP 755.
Section 8: Processes What is a process Creating processes Fork-Exec
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
Process Creation Process Termination
Tutorial 3 Tutorial 3.
Unix System Calls and Posix Threads
Process Programming Interface
Processes in Unix, Linux, and Windows
Processes in Unix and Windows
EECE.4810/EECE.5730 Operating Systems
EECE.4810/EECE.5730 Operating Systems
Presentation transcript:

March 1, 2002Serguei A. Mokhov, 1 Brief Introduction to System Calls and Process Management COMP229 - System Software Edition 1.1, March 11, 2002 Slides and examples could be found at:

March 1, 2002Serguei A. Mokhov, 2 Overview System Call Interface Process Management –fork() –exec() –wait() –exit()

March 1, 2002Serguei A. Mokhov, 3 System Call Interface User-running Kernel-running BlockedReady Zombie exit() syscall - trap read(), write(), wait(), sleep() App Software Sys Software OS Hardware API Sys Call (OS) Interface Sw-Hw I-face (drivers) “You are here”

March 1, 2002Serguei A. Mokhov, 4 The fork() System Call (1) A process calling fork() spawns a child process The child is almost an identical clone of the parent: –Text –Stack –PCB –Data

March 1, 2002Serguei A. Mokhov, 5 The fork() System Call (2) fork() is one of the those system calls, which is called once, but returns twice! After fork() both the parent and the child are executing the same program. On error, fork() returns -1 PID=28 p1 PID=28 p1 PID=34 c1 fork() Consider a piece of program (see fork_pid.c example):... pid_t pid = fork(); printf(“PID: %d\n”, pid);... The parent will print: PID: 34 And the child will always print: PID: 0

March 1, 2002Serguei A. Mokhov, 6 The fork() System Call (3) Remember, after fork() the execution order is not guaranteed. Simple fork() examples: –fork_pid.cprints out return from fork() –fork_child.cdistinguishes between the parent and the child

March 1, 2002Serguei A. Mokhov, 7 The exec() System Call (1) The exec() call replaces a current process’ image with a new one (i.e. loads a new program within current process). The new image is either regular executable binary file or a shell script. There’s no a syscall under the name exec(). By exec() we usually refer to a family of calls: –int execl(char *path, char *arg,...); –int execv(char *path, char *argv[]); –int execle(char *path, char *arg,..., char *envp[]); –int execve(char *path, char *argv[], char *envp[]); –int execlp(char *file, char *arg,...); –int execvp(char *file, char *argv[]); Here's what c, l, e, and p mean: –l means an argument list, –v means an argument vector, –e means an environment vector, and –p means a search path.

March 1, 2002Serguei A. Mokhov, 8 The exec() System Call (2) Upon success, exec() never returns to the caller. If it does return, it means the call failed. Typical reasons are: non-existent file or bad permissions. Arguments passed via exec() appear in the argv[] of the main() function. For more info: man -S 3 exec ; Example is: exec_pid.c PID=28 p1 PID=28 p1 exec() Old Program New Program Legend:

March 1, 2002Serguei A. Mokhov, 9 Environment The e exec calls use the environment when attempt to invoke a new program. Name = Value –HOME –PATH –SHELL –USER –LOGNAME –... set or env - will display current environment, which you can modify with: –the export command in a shell or a shell script; –getenv(), setenv(), putenv(), etc in C

March 1, 2002Serguei A. Mokhov, 10 fork() and exec() Combined Often after doing fork() we want to load a new program into the child. E.g.: a shell. PID=28 p1 PID=28 p1 PID=34 c1 fork() tcsh PID=34 c1 PID=34 c1 exec(ls) tcshls

March 1, 2002Serguei A. Mokhov, 11 The System wait() Call Forces the parent to suspend execution, i.e. wait for its children or a specific child to die (terminate is more appropriate terminology, but a bit less common). Example: fork_exec.c

March 1, 2002Serguei A. Mokhov, 12 The exit() System Call This call gracefully terminates process execution. Gracefully means it does clean up and release of resources, and puts the process into the zombie state. By calling wait(), the parent cleans up all its zombie children. exit() specifies a return value from it’s program, which a parent process might want to examine as well as status of the dead process. _exit() call is another possibility of quick death without cleanup.

March 1, 2002Serguei A. Mokhov, 13 Process Overview User-running Kernel-running BlockedReady Zombie exit() syscall() - trap wait() PID=1 INIT ?