DOC PREVIEW
FSU COP 5570 - Lecture Notes

This preview shows page 1-2-3-4-5-6 out of 19 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 19 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 19 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 19 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 19 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 19 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 19 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 19 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

Today’s TopicsComputer systems OverviewProcessWhat else in a process?Why process?Examining Processes in UnixCreating a New Process - fork()Points to NoteSlide 9Running an existing command in a program – exec()ExamplesProperties of exec()Running a command without killing the processSlide 14Running a command without killing the process?Running a command without killing the process, see example3.c, fixing example3b.cTerminating a processParent/child synchronizationPowerPoint PresentationToday’s Topics•Finishing the previous lecture•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 processesComputer systems Overview UserSpaceOSCPU schedulingMemoryMgmtFile systemDeviceMgmtProcessesNetwork StackSystem Call InterfaceProcess•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:–Memory space (static, dynamic)–Procedure call stack–Open files, connections–Registers and counters :•Program counter, Stack pointer, General purpose registers–……Why process?•Allowing multiple processes (users) to share the system resources.•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.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[]);Examples•Running one command example3a.c•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 processRunning a command without killing the processParentRunning a command without killing the process?ParentChildFork(…)Running a command without killing the process, see example3.c, fixing example3b.cParentChildFork(…)Exec(…)New programimagein executionTerminating 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.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• 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


View Full Document

FSU COP 5570 - Lecture Notes

Download Lecture Notes
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Lecture Notes and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Lecture Notes 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?