|
|
ProcessesFriday, September 10, 2004
Processes in UnixA program is just a file to Unix. In other words, when a user creates a source program and then compiles it, the program resides on disk as an executable file. The term process is used to describe a program that is actually running within the purview of Unix. For example, when a user requests that a program be run in Unix, Unix must load the program from the executable file on disk where it resides, build appropriate data structures to keep track of that program as it runs, and then start it running. To Unix, then, a process is just a (fairly complex) data structure in which Unix keeps all of the information about the status of the program that is running. Process Creation in Unix: The fork System CallIn order to begin understanding how Unix deals with processes, one must learn how Unix creates processes in the first place. That is, how does Unix start a program (an executable file on disk) running? We used the following two examples to discuss this.
In this example of Figure 1.3 we see how a program must call various functions in order to do tasks that require accessing hardware and are therefore only available through services provided by the operating system. the printf, exit, and open are all examples of such calls. Internally the functions accessed by these calls must have, in their machine language form, the equivalent of a TRAP instruction, which does the actual call to the Unix system service in question.
In Figure 1.4 we see an example of the fork() system call. The fork call accesses the fork service in Unix, which
When the child process, P50, starts running it does so by returning from the call to fork() with a return value of zero. This means that it executes the exec1 system call, which
When the parent process, P25, resumes running it does so by returning from the call to fork() with a nonzero return value. This means that P25 executes the wait system call. This again causes a Unix service to be accessed which "puts this process to sleep" by putting its data structure into a wait queue. When the child process (P50) finishes executing, Unix will wake up any process (including P25) that was waiting for P50 to finish and put the data structure for that process (e.g., P25) on the ready to run queue. |
|
|