Unix Processes
Processes
Unix is a multi-user as well as multitasking system. This means in which more than one user can use the system and every user can perform a number of tasks at the similar time. In UNIX system, a task is referred to as a process. A process is the existence of an executing program in the computer.
Because the CPU can hold out one task at a time, multitasking is completed using the concept of time- sharing. A UNIX Kernel maintains a list of processes begins through a user and each process is allocated a small time quantum, known as time slice, during that it can carry out its execution. Whenever its time elapses, the first procedure is suspended and other is provided a chance to run. Whenever all processes in the list have had their changes to run, the kernel switches back to the first process, beginning the execution from where it was suspended. By way, every process is permitted to work its way to completion, a little bit at a time.
The time slice for every process is so small (a few hundredths of a second), it provide the impression in which each user is being served concurrently, even though, they are being served one at a time.
There are several kinds of processes which can be beginning concurrently through a user. These processes fall into the following types:
Foreground processes- processes with that the user directly interacts.
Background processes- processes which are dissociated from the terminal.
Suspended processes- processes that execution has been suspended for although.
Foreground Processes
A foreground process is the one in that the user interfaces along with, from the keyboard. The user writes a command at the # prompt and waits till the execution is over.
Whenever the command is issued, it will get executed and the conclusion is echoed to the screen.
Background Processes
A background process can be beginning with a foreground procedure. When a command is appended with an & (ampersand) sign, it gets dissociated from the terminal and holds its execution in the background.
Let consider the following example
# sort data > /tmp/out & [1] 1074
#
[1] + Done(0) cat data 1>/tmp/out
#
The above command sorts the file data and redirects the output to another file out. This all process is appended through an &, implying which it has to be carried out in the background. Whenever a process is sent to the background a UNIX automatically shows a unique number which identifying that process, known as process id (PID). In the given instance, it is 1074. After displaying the PID number, the terminal is instantly available to the user (denotes by the # sign).
It is useful to hold out those processes in the background that do not need user input so that, in the meantime, another procedure can be executed in the foreground. For instance, printing a huge document in the background although editing another document in the foreground.
Suspended Processes
A user can suspend a job running in the background or one running in the foreground. This is useful whenever the user is running a command and a few other functions required to be performed. A running job can be suspended through pressing Ctrl-Z.
Switching between Processes
Sometimes a process might have to be brought from its suspended state to its running state, either in the foreground or background. This can be complete through using fg and bg commands. To know those processes are in background or in a suspended state and the jobs command can be used.