In an examination it is stated:
Give 2 different ways that a process can terminate normally. Describe the differences.
What is meant with terminate normally?
|
|
The term 'normally' used in this context typically means that an executing process exits when having completed all its instructions successfully, without e.g. being killed by signals or crashing unexpectedly. For example: This contrasts a process that for instance does not complete all the instructions and exits in non-deterministic manner. This can be caused by programmatic errors or it can be caused by signals issued by other processes to kill it. An abnormal termination is often determined in the logic implemented in the program e.g. a child process aborts/exits to the parent process with some return value Here the process abstraction is similar to a programmatic function in that they both share the ability to return a value to the calling process e.g. a shell. The semantics of these return values defines what qualifies a "successful" or a "unsuccessful" call. So in this case it's the programmer who is left with the responsibility for defining or using these semantics. To make a concrete example: a command executed from There are also other things to consider when talking terminating processes, such as freeing allocated address space with associated resources in memory, plus cpu scheduling of jobs, but that's another chapter. |
||||
|
|
I'm not sure what schools teach these days, but I would guess that terminate normally means "exit with 0 (zero) status". I can think of 3 ways to do this (at least in a C program):
I think (1) and (2) are just about equivalent, but (3) causes a process to exit without flushing its output buffers. You'd use this in the case of a fork/exec situation to avoid double-output of any bytes buffered up (by kernel or stdio) before the child process exits. |
|||
|
|
|
In order to terminate a process, a signal is sent to it. For most of these signals, the process can catch such signal, do some stuff ( release network resources, print good bye) and (most of time) terminate. What I have described is a way for a process to be killed gracefully, or normally. The process can also terminate if it has finished its job, or using a "x" button on GUI program. But since this is unix related site, I'm guessing otherwise. Note, two signals can not be caught by process, SIGKILL and SIGSTOP. Termination by SIGKILL is consider not normal termination. Normal termination Non gracefull termination |
|||
|
|