How to Find Cpu Utilization in Linux With Command Line




Process machine is a term used to describe the applications or programs. For example, when we open the internet browser application such as Google Chrome, we can say it was a process, which is responsible for running the application Chrome, run and run until we close the browser.

Even when we execute the command "bash" of any kind, the new process will appear. If we open the same application 2 x or if you or your friend opened it in the same system, meaning there are two processes that are running.

Now we'll learn how to set up a process in Linux via the command line. This is so You need if you want to see what processes are up and running or you may want to see which processes are run by a specific user or if you want to find a process where the most burdening your system.

Step 1 – Showing the process of Linux
Keywords that are important to be studied before the start of this tutorial are:

1. PID – Process ID. Each process has a 5-digit number. This figure could runs out (we ran out of numbers) and repetitive. But at other times, there will be no more than one PID in the system.



2. The PPID – Process Parent ID. The ID of the process that started the process.

2 the most used commands to see the process is and ps. Difference is the more commonly used interactively and ps are more often used in script, combined with another bash command or similar.

"top" command top is probably one of the most basic, often used to display the top process which typically consume the most system resources. When we execute the command top in the terminal, we will see a window similar to this:


top is a stand-alone application, after the command is executed, the new layout will appear and will process several dafta constantly updated every second. The new layout is actually can be controlled via your keyboard. The following are some examples:

  • h – display Windows help (help) with all commands and other useful information 
  • space – if you press the SPACEBAR on your keyboard then the table process will be updated immediately without having to wait for a few seconds. 
  • f – Add field to display in the layout or remove some of the fields, so that the field is not displayed. 
  • q – exit the application or additional window top that is part of the top application. For example, after You use the f. 
  • l – Menghidup or turn off the average load of information and information uptime. 
  • m – Menghidup/turn off memory information.
  • P (Shift + p) – Sorts based on the order process CPU usage 
  • s – Replace jenda between each refresh (you will be prompted to enter the number of seconds).
With the top command, you can also use several options such as:
  • -d delay – refresh interval determines in part the delay
  • -n number – refresh the page as much as the number of times and get out
  • -p pid – only displays and monitors the processes that have the process id (pid).
  • -q exit directly without pause.
For information on the use of other commands via keyboard, please refer to this website.

You can also use the command "man top" to display helpful information related to this command.

Use the command "top" also could be for:
  • Showing the process of the specified user. Type: "top -u user"
  • To turn off the process that is under way, after entering the application the "top", find "pid" from the process that you want to turn off and press the "K" on the keyboard. You will be asked to press the Enter key before "process id" is turned off.
  • You can save the settings command "top" by pressing the key combination "Shift + W". The settings will be stored in "/root/.toprc"
ps – ps is the other commands that are useful for displaying process on Linux. The following are some of the common use of his:
  • -e – Displays all processes.
  • -f – display all info with a complete format
  • -r – show only running processes
  • -u – an option to use a specific username
  • --pid – Options to filter based on process ID
  • --ppid – Options to filter based on parent process ID
  • -c – Mem-filter process based on its name or command
  • -o – Displays information related to specific keywords, separated by spaces or commas.
The following are some examples of the use of the "ps" command:
1. ps -ef – displays the processes that are running at the moment. ( Other similar Commands is ps aux )
2. ps -f -u user1,user2 – Showing all processes based on UID (User ID or username)
3. ps -f --pid id – Displays the process based on a process ID (pid). Enter an ID in the id section.
4. ps -c command/name – Mem-filter process based on its name or command
5. px aux --sort =-pcpu,+ pmem – Showing the most burdening the CPU processes
6. ps -e -o pid,uname,pcpu,pmem,comm – Used to filter specific columns you want to display.
7. ps -e -o pid,comm,etime – this will display the amount of time used by the process, calculated starting from when the start.

We recommend that you check this page for more detailed information, along with the use of the ps command.

Step 2 – switch off and set the priority of the process
Earlier we already learn how you can turn off the process of with the top command. You can also do this with the command "kill". As an example:

"kill pid" – at the PID, you can enter the ID of the process that you want to turn off. If the process crashes or could not be turned off, you can use: "kill -9 pid"

Other commands you can use is "NICE". Basically, this command allows you to prioritize the process if you are running the "many" in your system. In this way, your system will know where the process is more important and will run the first time. This command helps you to prioritize processes that are "important", rather than a process that is less important. For processes that have a lower priority, the system will only run it if there is a chance to run it (if there is a slot on the CPU that are not used). In this command, you can enter a value ranging from "-20 s/d 19". The lower the value, the higher the precedence in the process (remember, in school ranking 1 better than the rank 10). The priority of the default of "all" process is 0. The command is:

nice -n 'nilai Nice' process name – example: nice -n 10 name. This command will start a new process without being given priority.

If there are several running processes in the system and you want to give it a different value from the beginning, you can use the command: renice 'nilai Nice' -p 'PID' – Example: renice '10' -p '54125'

You have learned how to process management in Linux. There are so many different ways that you can combine and you use with commands available. So, feel free to try.


Next
Previous
Click here for Comments

0 comments: