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

Slides:



Advertisements
Similar presentations
Recitation 8 (Nov. 1) Outline Process & job control Lab 5 Reminder Lab 5: Due Thursday Minglong Shao Office hours: Thursdays 5-6PM.
Advertisements

Recitation 8: 10/28/02 Outline Processes Signals –Racing Hazard –Reaping Children Annie Luo Office Hours: Thursday 6:00.
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.
CS 311 – Lecture 14 Outline Process management system calls Introduction System calls  fork()  getpid()  getppid()  wait()  exit() Orphan process.
CPSC 451 Editors and Systems Calls1 Minix editors Mined - (mined) is a simple screen editor. Elle - (elle) is a clone of Emacs. Elvis - (elvis, ex, vi)
Source: T.Y. Wong, Chinese University of Hong Kong Supplementary materials: Command shell using fork, exec, and wait.
Exec function Exec function: - replaces the current process (its code, data, stack & heap segments) with a new program - the new program starts executing.
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.
CSSE 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 Control. Major Requirements of an Operating System Interleave the execution of several processes to maximize processor utilization while providing.
Process in Unix, Linux, and Windows CS-3013 A-term Processes in Unix, Linux, and Windows CS-3013 Operating Systems (Slides include materials from.
March 1, 2002Serguei A. Mokhov, 1 Brief Introduction to System Calls and Process Management COMP229 - System Software Edition 1.1,
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.
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
Agenda  Working with Processes: Purpose Running Programs within same process (execl, execlp, execle, execv, execvp, execve) “Spawning” other process (fork,
System calls for Process management
Operating Systems Processes 1.
Unix Process Model Simple and powerful primitives for process creation and initialization. fork syscall creates a child process as (initially) a clone.
Scis.regis.edu ● CS 468: Advanced UNIX Class 5 Dr. Jesús Borrego Regis University 1.
Linux Processes Travis Willey Jeff Mihalik. What is a process? A process is a program in execution A process includes: –program counter –stack –data section.
Copyright ©: Nahrstedt, Angrave, Abdelzaher1 Processes and Threads.
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,
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.
1 A Seven-State Process Model. 2 CPU Switch From Process to Process Silberschatz, Galvin, and Gagne  1999.
CSCI 330 UNIX and Network Programming
S -1 Processes. S -2 wait and waitpid (11.2) Recall from a previous slide: pid_t wait( int *status ) wait() can: (a) block; (b) return with status; (c)
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.
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
Fork and Exec Unix Model
LINUX System Programming with Processes (additional)
Processes in Unix, Linux, and Windows
Process Creation Process Termination
Tutorial 3 Tutorial 3.
Unix System Calls and Posix Threads
Processes Prof. Ikjun Yeom TA – Mugyo
Processes in Unix, Linux, and Windows
Processes in Unix and Windows
EECE.4810/EECE.5730 Operating Systems
System Programming: Process Management
Presentation transcript:

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

Processes 2

3 The fork() System Call (1) A process calling fork() spawns a child process. The child is almost an identical clone of the parent: –Program Text (segment.text) –Stack (ss) –PCB (eg. registers) –Data (segment.data) #include pid_t fork(void);

4 The fork() System Call (2) The 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 After fork() the execution order is not guaranteed. PID=28 p1 PID=28 p1 PID=34 c1 fork() Consider a piece of program... pid_t pid = fork(); printf( “ PID: %d\n ”, pid);... The parent will print: PID: 34 And the child will always print: PID: 0

5 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 l, v, 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.

6 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 (bad path) or bad permissions. Arguments passed via exec() appear in the argv[] of the main() function. For more info: man 3 exec ; PID=28 p1 PID=28 p1 exec() Old Program New Program Legend:

7 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

8 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).

9 The System wait() Call (2) The wait() causes the parent to wait for any child process. The waitpid() waits for the child with specific PID. The return value is: –PID of the exited process, if no error –(-1) if an error has happened #include pid_t wait(int *status); pid_t waitpid(pid_t pid, int *status, int options);

10 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 the program, which a parent process might want to examine as well as status of the dead process. #include void exit(int status);

The pause() system call Used to suspend process until a signal arrives Signal action can be the execution of a handler function or process termination only returns (-1) when a signal was caught and the signal-catching function returned 11 #include int pause(void);

Process states Zombie: has completed execution, still has an entry in the process table Orphan: parent has finished or terminated while this process is still running Daemon: runs as a background process, not under the direct control of an interactive user 12

Zombie process 13

Signals 14

Process interaction with signals Unix supports a signal facility, looks like a software version of the interrupt subsystem of a normal CPU Process can send a signal to another Kernel can send signal to a process (like an interrupt) Process can handle or ignore a given call Handle a signal by binding a function to the arrival of a designated signal 15

Sending a signal: kill() system call 16

Handling signals: signal() 17

Assignment 1 tips 1.First experiment with fork() and getpid(), getppid() 2.Use simple printf statements to distinguish parent from child (through pid) 3.Send simple signal to child 4.Create signal handlers 1.For 1 st time called ( “starting – pid’) 2.For all other times called (“process – pid”) 3.To handle Ctrl-C 4.For termination of child process 5.Create logic for alternating execution 18