- A running program needs to be able to halt its execution either normally (end) or abnormally (abort). If a system call is made to terminate the currently runing program abnormally, or if the program runs into a problem and causes an error trap, a dump of memory is sometimes taken and an error message generated.
- A process or job executing one program may want to load and execute another program.
- An interesting question is where to return control when the loaded program terminates. This question is related to the problem of
whether the existing program is lost, saved, or allowed to continue execution concurrently with the new program.
- There are so many facets of and variations in process and job control that we next use two examples to clarify these concepts.
- one involving a single-tasking system
- the other a multi-tasking system
- The MS-DOS OS is an example of a single-tasking system. It has a command interpreter that is invoked when the computer is started (see Fig. 2.35(a)).
- Because MS-DOS is single-tasking, it uses a simple method to run a program and does not create a new process. It loads the program into memory, writing over most of itself to give the program as much memory as possible (see Fig. 2.35(b)).
Figure 2.35:
MS-DOS execution. (a) At system start-up. (b) Running a program.
|
- Next, it sets the instruction pointer to the first instruction of the program. The program then runs, and either an error causes a trap, or the program executes a system call to terminate.
- FreeBSD (derived from Berkeley UNIX) is an example of a multitasking system. When a user logs on to the system, the shell of the user's choice is run.
- This shell is similar to the MS-DOS shell in that it accepts commands and executes programs that the user requests. However, since FreeBSD is a multitasking system, the command interpreter may continue running while another program is executed (see Fig. 2.36).
Figure 2.36:
FreeBSD running multiple programs.
|
- To start a new process, the shell executes a fork() system call. Then, the selected program is loaded into memory via an exec() system call, and the program is executed.
Cem Ozdogan
2011-02-14