CS 311 - Lecture 15 Outline Process Management System calls – exec() – chdir() – system() – nice() – Accessing User and Group IDs – Redirection Lecture.

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

1 CS345 Operating Systems Φροντιστήριο Άσκησης 1.
UC Santa Barbara Project 1 Discussion Bryce Boe 2011/04/12.
Process Control Hua LiSystems ProgrammingCS2690Process Control Page 1 of 41.
1 Processes Professor Jennifer Rexford
1 Processes and Pipes COS 217 Professor Jennifer Rexford.
CS 311 – Lecture 14 Outline Process management system calls Introduction System calls  fork()  getpid()  getppid()  wait()  exit() Orphan process.
CS 311 – Lecture 09 Outline Introduction to Systems programming – System calls – Categories of system calls Error Management System calls File Handling.
CS 311 – Lecture 13 Outline File management system calls chown() chmod() dup() and dup2() link() Lecture 131CS Operating Systems 1.
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.
Process Control in Unix Operating Systems Hebrew University Spring 2004.
CSSE Operating Systems
Shells, System Calls, and Signals. What is a Shell? A shell is a command line interface to the operating system – Fetch a command from the user and execute.
Unix Processes operating systems. The Process ID Unix identifies each process with a unique integer called a process ID. The process that executes the.
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.
1 UNIX System Programming v Objectives –look at how to program UNIX processes –fork( ), exec( ), wait( ) Processes.
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.
Simple Shell Part 1 Due date (75%): April, 2002 Part 2 Due date (25%): Apr 5, 2002.
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
Pipes A pipe is a simple, synchronized way of passing information between processes A pipe is a special file/buffer that stores a limited amount of data.
8-Sep Operating Systems Yasir Kiani. 8-Sep Agenda for Today Review of previous lecture Process scheduling concepts Process creation and termination.
Process Control Process identifiers Process creation fork and vfork wait and waitpid Race conditions exec functions system function.
ICS 431 – Operating System. a command-line interpreter. a program that interprets commands and acts as an intermediary between the user and the inner.
Lecture 24CS311 – Operating Systems 1 1 CS311 – Lecture 24 Outline Final Exam Study Guide Note: These lecture notes are not intended replace your notes.
Chapter 11 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.
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
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.
CSCI 330 UNIX and Network Programming
Tutorial 3. In this tutorial we’ll see Fork() and Exec() system calls.
KUKUM Real Time System Module #3 POSIX programming with Linux Lecture 1.
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.
S ALVATORE DI G IROLAMO (TA) Networks and Operating Systems: Exercise Session 1.
Linux/UNIX Programming APUE (Process Control) 문양세 강원대학교 IT 대학 컴퓨터과학전공.
CSCI 4061 Recitation 2 1.
Implementation of a simple shell, xssh
Implementation of a simple shell, xssh (Section 1 version)
LINUX System : Lecture 8 Programming with Processes
Implementation of a simple shell, xssh
Linux Processes & Threads
Real Time Programming Tech.
Using Processes.
Unix Process Management
UNIX PROCESSES.
Sarah Diesburg Operating Systems CS 3430
Project1: Unix Shell using Multi-Processing
Shells, System Calls, and Signals
Fork and Exec Unix Model
Operating Systems Lecture 6.
Tutorial 3 Tutorial 3.
제11장 프로세스 관리.
Process Programming Interface
Advanced Uses of Pointers
EECE.4810/EECE.5730 Operating Systems
EECE.4810/EECE.5730 Operating Systems
System Programming: Process Management
Presentation transcript:

CS Lecture 15 Outline Process Management System calls – exec() – chdir() – system() – nice() – Accessing User and Group IDs – Redirection Lecture 151CS Operating Systems I

Differentiating a process: exec() exec() system call replaces the code of a process with another process. Prototype of exec() int execl (const char* cmd_path, const char* arg0, const char* arg1,..., const char* argn, NULL) int execv (const char* cmd_path, const char* argv[ ]) Uses the absolute or relative pathname to commands. int execlp (const char* cmd_path, const char* arg0, const char* arg1,..., const char* argn, NULL) int execvp (const char* cmd_path, const char* argv[ ]) Uses $PATH variable to find commands Lecture 152CS Operating Systems I

Examples for exec() To execute a command say “ls –l –a directory” execl (“/bin/ls”, “ls”, “-l”, “-a”, “directory”, NULL); char *argv []= {“ls”, “-l”, “-a”, “directory”, NULL}; execv (“/bin/ls”, argv); uses $PATH variable to find ls command execlp (“ls”, “ls”, “-l”, “-a”, “directory”, NULL); execvp (argv[0], argv); Returns -1 if failure. Lecture 15CS Operating Systems I3

Change directory: chdir() chdir() changes directory A child inherits current working directory from its parent. Syntax: int chdir (const char* pathname) chdir () returns 0 if successful; otherwise, it returns -1 Lecture 15CS Operating Systems I4

system() You can use the system() function to execute UNIX/Linux commands from a C program. Syntax: system(“command”) Example: system(“pwd”) Lecture 15CS Operating Systems I5

Change process priority: nice() Every process has a priority value between -20 and +19. Lower the priority faster the process gets scheduled. nice() changes the priority value of the process. Syntax: int nice(int delta) Delta is added to the current priority value of the process. Lecture 15CS Operating Systems I6

Accessing user and group IDs Getting user and group IDs uid_t getuid () – get real user ID uid_t geteuid () – get effective user ID gid_t getgid () gid_t getegid () Setting user and group IDs int setuid (uid_t id) int seteuid (uid_t id) int setgid (gid_t id) int setegid (gid_t id) Lecture 15CS Operating Systems I7

Redirection Steps that occur in background when executing ls > ls.out – The parent shell forks and then waits for the child shell to terminate. – The child shell opens the file "ls.out," creating it or truncating it as necessary. – The child shell then duplicates the file descriptor of "ls.out" to the standard output file descriptor, number 1, and then closes the original descriptor of "ls.out". – The child shell then exec's the ls utility. – When the child shell terminates, the parent resumes. The parent's file descriptors are unaffected by the child's actions. Lecture 15CS Operating Systems I8