Linux Processes
By harshit90
![]() | Amazon Price: $0.99 |
![]() | Amazon Price: $80.87 |
![]() | Amazon Price: $44.41 List Price: $64.99 |
![]() | Amazon Price: $87.11 List Price: $170.00 |
![]() | Amazon Price: $19.28 List Price: $29.95 |
Amazon Price: $29.99 |
Any process is said to be in a particular state at any instant of time, there are 6 states of any process. These are
1.)When you execute the process the scheduler send your process to a queue called the process queue, at this stage the process is said to be in the submit state.
2.)Once submitted the process awaits its turn in the queue ie. it awaits the turn when it will begin execution, during this wait the process is said to be in the hold state.
3.)As the process advances, at some point of time it will become the next process to be executed in the queue, at this stage the process is said to be in the ready state.
4.)When the process gets CPU attention and starts running it will be called as a process in the run state.
5.)While running the process it might so happen that the time slice alloted to the process might get over and CPU will allot the time to another process, at this point of time the orignal process is said to be in the ready state and is returned to the queue.
6.)Some processes will involve input/output operations, during these operations the CPU will remain idle , this is undesirable and during this time the process will be in the wait state and the CPU time slice will be given to another process.
7.)A process whose execution comes to an end is said to go into the complete state, and this process is removed from the process queue.
View Current processes- You can view all the processes that are running currently by using the " ps" command. the switch "e" and "f" are used to display details of these processes
Why does the output of the ps command has the ps itself ?
This is because when the snapshot of the memory is taken by ps for all the processes running,the process ps is bieng executed and hence ps will be included as one of its outputs, this is like ps is recursively viewing itself in the snapshot of the memory it took.
Background Processes, What are they ?
A process in Linux can be run in the background as a deamon, to do this you need to proceed a command with an "&" ie. at the end of the command just add an &. This will give you a number and then show you the prompt again, this number shown is the pid of the process.
Disadvantages of background processes
1.) The output of any background process should always be redirected to a file this is because if this is not done then you will get a garbled screen with the output of the deamon process.
2.) The shell will never tell you the success of the process or if the process was prematurely terminated, you would have to use the pid given to see this.
**Warning
When you logout any background process that you might have started which is not complete will be terminated which is obvious because all processes are grandchildren ,children and so on of the shell process.
A solution to the problem-
But if you want a process (executing in the background) to continue even when you logout then you have to use the nouhp command
syntax : nouhp "command"
This will execute the command in the background and if the command is a huge process then it will continue executing even when you logout.
nouhp stands for "No Hangups"
if an output file to a process executed using nouhp is not specified then by default the output of the process is placed in the file called nouhp.out
*If nouhp is used in pipeline processes then all processes in the pipeline should be declared with nouhp, why ?
This is because when you logout , if any process in the pipeline ends(which is not preceeded by nouhp) then the whole pipeline is bound to collapse.
Kill The Process-
The kill command is used to kill(or end) a process which is no longer required.
syntax: kill pid
When a kill command is executed, it sends a kill end(terminate) signal to end the process, if you dont specify this kill signal then the default kill signal is used, but sometimes the default kill signal might not be enough to kill a process , in such a case the kill number "9" is used.
eg : kill -9 pid (hence the signal 9 will result in a "sure kill")
The killall command is used to kill a process by its name, ie.
killall process_name
will kill the process which is running by the name of "process_name"
*How to change the the priority of a process ??
The priority of a process which is to be run can be changed using the command "nice". The higher the nice value of the process the lower will be its priority.
A normal user can only increment the nice value of a process therby reducing its priority, this can be done like-
nice -15 cat employee.dat
this will increment the nice value of this process by 15, this specified increment value can range from 0-19, also if this increment value is not specified then the nice value will be by default be incremented by 10.
Only the super user can decrement the nice value of a process therby increasing its priority, the eg is
nice --10 sort employee.dat
this will reduce the nice value of the process by 10 and thus increase its priority.
To view the nice value of a process the command is ps -l.
Comments
No comments yet.




