Any process can either be terminated normally or abnormally.
A process can be terminated in one of the following ways:
- by exiting (i.e., the process terminates itself calling exit system call)- Normal Termination
- by being signaled –Abnormal Termination
- by having no running threads (i.e. the thread count goes to 0)
Normal Terminations:
- This reflects that the process has completed its task and has terminated gracefully.
- The exit() system call is used by most operating systems for process termination.
- The process leaves the processor and releases all its resources
Abnormal Terminations:
This reflects that the process has not completed its task rather it has terminated in between because of any other reasons.
Some of the common reasons for abnormal terminations are:
- The process is trying to access some memory locations which it should not, resulting in a SIGSEGV signal.
- Termination because of permissions that is read-write permissions.
- Another process explicitly sends a signal to the process that is with kill(pid, SIGTERM).
- Trying to bypass the System call API accessing the kernel.
The most common utility to terminate a process is “kill” command.
- The kill command is used to send a signal to processes.
- The most frequently used signal is SIGKILL or -9, which terminates the given processes.
Syntax:
$ kill -<signal_name_or_signal_number> PID_OF_PROCESS
Options can be fetched by command kill -l
Signals can be specified in three different ways:
- Using numbers (eg : -1 or -9)
- Using the “SIG” prefix(eg: SIGHUP or SIGKILL or SIGTERM)
- Without using the “SIG” prefix( eg: HUP or KILL or TERM)
Example:
- kill -9 <pid> or kill -SIGTERM <pid>
- kill -SIGTERM <pid>
- kill -TERM <pid>
All the above are equivalent.
Values of PID:
- If the value of PID is greater than 0, the signal is sent to a specific process with that ID
- If the value of PID is 0, the signal is sent to all the processes in the current group.
- If the value is -1 the signal is sent to all processes with the same UID as the user invoking the command.
- If PID is less than -1, the signal is sent to all processes in the process group equal to the absolute value of the PID that is if PID is -9 then the signal will be sent to process id 9 in the current process group eq to GID.
Related Posts:
- Process vs program
- Sections of a process
- States of a process
- Process Control Block(PCB)
- Attributes of a process
- Context switching
Categories: Operating system (OS)
Leave a Reply