Linux Background Process
Linux is a multitasking operating system running various process at once, including foreground to background process. Its shell also allows the user to interact with the environment and put the desired process foreground or background or even kill.
Firstly list the process running by the command ps. PID values must be know to kill a certain process. Linux processes can run either "with shell" or "without shell". "With shell" involves working of process only till the shell is open and "without shell" means even if the user closes the shell it will keep on running in the background. The important fact here is that if you open two terminals in use one to create a background process, then it can be killed from another terminal too. So the processes aren't limited to the particular terminal where it has been executed.
What is ps command?
After running the ps command, we would get the following output:
( Root is not necessary here, although) Thus we get the entries with time and with commands
One may also use top command and get this output:
Even the command pstree will show you process and their connections with each as this:
Very well, now we can move to create a background process
To create any background process the user has to enter the command and end it with "&" after leaving a space.
So we launch :xload" application in the background by the command
xload &
Here in square brackets I have 3 because it was my 3rd background process. Now to check your background process.
Type the command - jobs
Gotcha! The 3rd is "xload" process and is running.
Now to kill it
Type the command kill <Signal> <process ID>
So kill -9 4153
Now to kill it
Type the command kill <Signal> <process ID>
So kill -9 4153
Here 4153 is my PID and the result is:
Kill -20 <PID value> will just suspend the process similarly to CTRL+Z
<Kill -9 PID value> will kill the process
<Kill -18 PID value> value will kill the process
Now to bring this to foreground
Type the command
fg <process ID>
And Voila! Your process will bump forward and start.To move the process in the background firstly we click CTRL+Z to suspend the application then
Type
bg
and it will run in the background.One must remember that a PID is not a job number.
With this method, a process will run the background until shell is closed
To run a process in the background even if shell closes, then user has to
1. Run the command in the background
2. Type disown -h
3. Type exit
Note- Sometimes CTRL + Z wouldn't work then to get PID, one may also use the command ps -aux
Feel free to contact if anything is missing or wrong here.
So Long :)
To run a process in the background even if shell closes, then user has to
1. Run the command in the background
2. Type disown -h
3. Type exit
Note- Sometimes CTRL + Z wouldn't work then to get PID, one may also use the command ps -aux
Feel free to contact if anything is missing or wrong here.
So Long :)
No comments:
Post a Comment