Process Management Azzam Mourad COEN 346.

Slides:



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

Process Control Hua LiSystems ProgrammingCS2690Process Control Page 1 of 41.
1 Processes and Pipes COS 217 Professor Jennifer Rexford.
Exec function Exec function: - replaces the current process (its code, data, stack & heap segments) with a new program - the new program starts executing.
CS Lecture 15 Outline Process Management System calls – exec() – chdir() – system() – nice() – Accessing User and Group IDs – Redirection Lecture.
Process Control in Unix Operating Systems Hebrew University Spring 2004.
CSSE Operating Systems
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.
Process Control. Major Requirements of an Operating System Interleave the execution of several processes to maximize processor utilization while providing.
BINA RAMAMURTHY UNIVERSITY AT BUFFALO System Structure and Process Model 5/30/2013 Amrita-UB-MSES
Some Example C Programs. These programs show how to use the exec function.
The Programming Interface. Main Points Creating and managing processes – fork, exec, wait Performing I/O – open, read, write, close Communicating between.
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.
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.
1 Week 2 The Crunchy Shell to the Soft and Chewy Kernel… Sarah Diesburg 8/3/2010 COP4610 / CGS5765.
Creating and Executing Processes
CS 241 Section Week #2 9/9/10. 2 Topics This Section MP1 issues MP2 overview Process creation using fork()‏ Debugging tools: valgrind, gdb.
CE Operating Systems Lecture 10 Processes and process management in Linux.
Process Control Process identifiers Process creation fork and vfork wait and waitpid Race conditions exec functions system function.
Agenda  Working with Processes: Purpose Running Programs within same process (execl, execlp, execle, execv, execvp, execve) “Spawning” other process (fork,
ICS 431 – Operating System. a command-line interpreter. a program that interprets commands and acts as an intermediary between the user and the inner.
System calls for Process management
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.
Concurrent Processes Processes can concurrently run same program. Processes can concurrently run same program. Processes can start other processes. Processes.
Operating Systems Process Creation
1 Tutorial: CSI 3310 Dewan Tanvir Ahmed SITE, UofO.
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.
1 A Seven-State Process Model. 2 CPU Switch From Process to Process Silberschatz, Galvin, and Gagne  1999.
CSCI 330 UNIX and Network Programming
The Process CIS 370, Fall 2009 CIS UMassD. The notion of a process In UNIX a process is an instance of a program in execution A job or a task Each process.
Tutorial 3. In this tutorial we’ll see Fork() and Exec() system calls.
System calls for Process management Process creation, termination, waiting.
KUKUM Real Time System Module #3 POSIX programming with Linux Lecture 1.
Shell Execution Basic: fork, child execs, parent waits code of program in box –RC == return value from fork() Call fork RC=0 Call exec Subsequent instructions.
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.
Using System Calls (Unix) Have to tell compiler (if C/C++) where to find the headers, etc. – i.e., the “include” files May have to tell compiler where.
1 Intro to the Shell with Fork, Exec, Wait Sarah Diesburg Operating Systems CS 3430.
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” –
CSCI 4061 Recitation 2 1.
Protection of System Resources
Real Time Programming Tech.
Using Processes.
Unix Process Management
CSC 382: Computer Security
UNIX PROCESSES.
System Structure and Process Model
System Structure and Process Model
Lecture 5: Process Creation
Fork and Exec Unix Model
System Structure B. Ramamurthy.
System Structure and Process Model
Lab 5 Process Control Operating System Lab.
Tutorial 3 Tutorial 3.
Operation System Program 1
Process Programming Interface
Tutorial: The Programming Interface
Process Control B.Ramamurthy 2/22/2019 B.Ramamurthy.
Process Description and Control in Unix
EECE.4810/EECE.5730 Operating Systems
Process Description and Control in Unix
EECE.4810/EECE.5730 Operating Systems
System Programming: Process Management
Presentation transcript:

Process Management Azzam Mourad COEN 346

A. Mourad2 Agenda How to create and terminate a process Relation between a parent and child process The use of fork() and exec() family of functions Assignment 2 (part 2)

A. Mourad3 Assignment 2 (part 2 – a) Write a C/C++ program, called Asg2iia.cpp or Asg2iia.c that does the following: Executes as a parent process, which occurs naturally. The parent process must output the following statement: “Parent process is running and about to fork to a child process”. The parent process must then create a child process (using fork()). The child will simply print out to the standard output the following statement: ”I am the child process”. You are NOT allowed to use the exec calls in this part. That is, you must make sure that the child will still run the proper code to perform what it needs to do without the executions of any of the “exec” calls.

A. Mourad4 Assignment 2 (part 2 – a) Once the child starts, the parent must wait for the child to die before it continues. Output: Parent process is running and about to fork to a child process I am the child process Parent acknowledges child termination Parent will terminate now

A. Mourad5 Assignment 2 (part 2 – b) Write a C/C++ program, called “outsider.cpp” or “outsider.c” that outputs the following statement: “Outsider program is running. Write a C/C++ program called Asg2iib.cpp or Asg2iib.c, which is similar to the one you created in Part II-A above, with the following exceptions: The child process must execute the code of the Outsider program using the exec system call Output: Parent process is running and about to fork to a child process Outsider program is running. Time now is Mon Jan 29 01:16:26 EST 2007 Parent acknowledges child termination Parent will terminate now

A. Mourad6 Process Management A process is created for you program when you run it from a shell This is the parent process You can create child processes inside the program using the fork() command

A. Mourad7 Process Creation The fork() system call will spawn a new child process which is an identical process to the parent except that has a new system process ID. The process is copied in memory from the parent and a new process structure is assigned by the kernel. The return value of the function is which discriminates the two threads of execution. A zero is returned by the fork function in the child's process. The environment, resource limits, controlling terminal, current working directory, root directory and other process resources are also duplicated from the parent in the forked child process.

A. Mourad8 Process Creation (vfork) The vfork() function is the same as fork() except that it does not make a copy of the address space. The memory is shared reducing the overhead of spawning a new process with a unique copy of all the memory. The vfork() function also executes the child process first and resumes the parent process when the child terminates.

A. Mourad9 Process Creation using fork() #include using namespace std; main() { pid_t pID = fork(); if (pID == 0) // child { // Code only executed by child process} else if (pID < 0) // failed to fork { cerr << "Failed to fork" << endl; exit(1);} else // parent { // Code only executed by parent process} // Code executed by both parent and child }

A. Mourad10 Process Termination The C library function exit() calls the kernel system call _exit() internally. The kernel system call _exit() will cause the kernel to close descriptors, free memory, and perform the kernel terminating process clean-up. The C library function exit() call will flush I/O buffers and perform additional clean-up before calling _exit() internally. The function exit(status) causes the executable to return "status". The parent process can examine the terminating status of the child. The parent process will often want to wait until all child processes have been completed using the wait() function call

A. Mourad11 exec family of functions The exec() family of functions will initiate a program from within a program. The functions return an integer error code. (0=Ok / -1=Fail)

A. Mourad12 execl The function call "execl()" initiates a new program in the same environment in which it is operating. An executable (with fully qualified path. i.e. /bin/ls) and arguments are passed to the function. int execl(const char *path, const char *arg1, const char *arg2,... const char *argn, (char *) 0); #include main() { execl("/bin/ls", "-r", "-t", "-l", (char *) 0); } All function arguments are null terminated strings. The list of arguments is terminated by NULL.

A. Mourad13 execlp The routine execlp() will perform the same as execl except that it will use environment variable PATH to determine which executable to process. Thus a fully qualified path name would not have to be used. The first argument to the function could instead be "ls".

A. Mourad14 execv This is the same as execl() except that the arguments are passed as null terminated array of pointers to char. int execv(const char *path, char *const argv[]); #include main() { char *args[] = {"-r", "-t", "-l", (char *) 0 } execv("/bin/ls", args);}

A. Mourad15 execvp The routine execvp() will perform the same execv except that it will use environment variable PATH to determine which executable to process. Thus a fully qualified path name would not have to be used. The first argument to the function could instead be "ls".

A. Mourad16 execve The function call "execve()" executes a process in an environment which it assigns. Set the environment variables: Assignment: char *env[] = { "USER=user1", "PATH=/usr/bin:/bin:/opt/bin", (char *) 0 }; char *Env_argv[] = { "/bin/ls", "-l", "-a", (char *) 0 }; execve (Env_argv[], Env_argv, Env_envp);