What is Processes
Process is kind of program or task carried out by your PC. For e.g.$ ls -lR
ls command or a request to list files in a directory and all subdirectory in your current directory - It is a process.
Process defined as:
"A process is program (command given by user) to perform specific Job. In Linux when you start process, it gives a number to process (called PID or process-id), PID starts from 0 to 65535."
Why Process required
As You know Linux is multi-user, multitasking Os. It means you can run more than two process simultaneously if you wish. For e.g. To find how many files do you have on your system you may give command like:$ ls / -R | wc -l
This command will take lot of time to search all files on your system. So you can run such command in Background or simultaneously by giving command like
$ ls / -R | wc -l &
The ampersand (&) at the end of command tells shells start process (ls / -R | wc -l) and run it in background takes next command immediately.
Process & PID defined as:
"An instance of running command is called process and the number printed by shell is called process-id (PID), this PID can be use to refer specific running process."
Linux Command Related with Process
Following tables most commonly used command(s) with process:For this purpose | Use this Command | Examples* |
To see currently running process | ps | $ ps |
To stop any process by PID i.e. to kill process | kill {PID} | $ kill 1012 |
To stop processes by name i.e. to kill process | killall {Process-name} | $ killall httpd |
To get information about all running process | ps -ag | $ ps -ag |
To stop all process except your shell | kill 0 | $ kill 0 |
For background processing (With &, use to put particular command and program in background) | linux-command & | $ ls / -R | wc -l & |
To display the owner of the processes along with the processes | ps aux | $ ps aux |
To see if a particular process is running or not. For this purpose you have to use ps command in combination with the grep command | ps ax | grep process-U-want-to see | For e.g. you want to see whether Apache web server process is running or not then give command$ ps ax | grep httpd |
To see currently running processes and other information like memory and CPU usage with real time updates. | top See the output of top command. | $ top Note that to exit from top command press q. |
To display a tree of processes | pstree | $ pstree |
NOTE that you can only kill process which are created by yourself. A Administrator can almost kill 95-98% process. But some process can not be killed, such as VDU Process.
Exercise:
You are working on your Linux workstation (might be learning LSST or some other work like sending mails, typing letter), while doing this work you have started to play MP3 files on your workstation. Regarding this situation, answer the following question:
1) Is it example of Multitasking?
2) How you will you find out the both running process (MP3 Playing & Letter typing)?
3) "Currently only two Process are running in your Linux/PC environment", Is it True or False?, And how you will verify this?
4) You don't want to listen music (MP3 Files) but want to continue with other work on PC, you will take any of the following action:
- Turn off Speakers
- Turn off Computer / Shutdown Linux Os
- Kill the MP3 playing process
- None of the above
Answers :
1) Is it example of Multitasking?
Ans.: Yes, since you are running two process simultaneously.
2) How you will you find out the both running process (MP3 Playing & Letter typing)?
Ans.: Try $ ps aux or $ ps ax | grep process-you-want-to-search
3) "Currently only two Process are running in your Linux/PC environment", Is it True or False?, And how you will verify this?
Ans.: No its not true, when you start Linux Os, various process start in background for different purpose. To verify this simply use top or ps aux command.
4) You don't want to listen music (MP3 Files) but want to continue with other work on PC, you will take any of the following action:
Ans.: Use action no. 3 i.e. kill the MP3 process.
Tip: First find the PID of MP3 playing process by issuing command:
$ ps ax | grep mp3-process-name
Then in the first column you will get PID of process. Kill this PID to end the process as:
$ kill PID
Or you can try killall command to kill process by name as follows:
$ killall mp3-process-name
Ans.: Yes, since you are running two process simultaneously.
2) How you will you find out the both running process (MP3 Playing & Letter typing)?
Ans.: Try $ ps aux or $ ps ax | grep process-you-want-to-search
3) "Currently only two Process are running in your Linux/PC environment", Is it True or False?, And how you will verify this?
Ans.: No its not true, when you start Linux Os, various process start in background for different purpose. To verify this simply use top or ps aux command.
4) You don't want to listen music (MP3 Files) but want to continue with other work on PC, you will take any of the following action:
Ans.: Use action no. 3 i.e. kill the MP3 process.
Tip: First find the PID of MP3 playing process by issuing command:
$ ps ax | grep mp3-process-name
Then in the first column you will get PID of process. Kill this PID to end the process as:
$ kill PID
Or you can try killall command to kill process by name as follows:
$ killall mp3-process-name
No comments:
Post a Comment