functionality to the new pron Figure 3.9. However, UNIX shells typically also all w child process to run in the background, or concurrently. To accomplish this, we add an ampersand (t) at the end of the command. Thus, if we rewrite the above command as ave the parent process ns case, cat prog.c) command. Unless exit before contin- on illustrated in osh>cat prog.c the parent and child processes will run concurrently The separate child process is created using the fork ) system call, and the user's command is executed using one of the system calls in the exec ) family (as described in Section 3.3.1). AC program that provides the general operations of a command-line shell is supplied in Figure 3.36. The main() function presents the prompt osh-> and outlines the steps to be taken after input from the user has been read. The main) function continually loops as long as should run equals 1; when the user enters exit at the prompt, your program will set should run to 0 and terminate. #include <stdio.h> #include <unistd.h> sdefine MAX.LINE 80 /The maximun length command / int main(void) ( char args [MAX.LINE/2 1]: /command 1ine arguments int should run 1; /11ag to deternine vhen to exit progran while (should run) printf("osh>"); tush(stdout); After reading user input, the steps are: (1) fork a child process using fork) (2) the child
process vill invoke execvp) .(3) parent will invoke wait) unless command included & return 0; perating-system-concepts-10th.pdf A Page view Fit to page TIgiaunng riojecis This project is organized into several parts in the child 1. Creating the child process and executine Providing a history feature Adding support of input and output odirecun Allowing the parent and child processes to com 2 3. 4. via a pipe II. Executing Command in a Child
You've reached the end of your free preview.
Want to read all 6 pages?
- Fall '19
- Exit, Child process