It helps us to determine which process is doing what in our system, how much memory it is using, how much CPU space it occupies, user ID, command name, etc. The ps command is used to view currently running processes on the system. Root 1007 0.0 0.6 943636 40296 ? Ssl Nov01 0:45 /usr/lib/snapd/snapdĮven if the ps command's flexibility meets your needs, you can always create aliases so that you don't have count columns and/or think about whether column values are numeric.Next → ← prev ps Command in Linux/Unix with Examples $ ps aux | head -1 ps aux | sort -r -nk 4 | head -6 ![]() The sort command uses "-nk 4" to (-n) sort numerically on the (-k 4) 4 th data column in the sort output. The ps command understand this distinction sort does not and needs to be nudged.Ī command like this one would sort on memory usage. There are a couple of downsides to this approach: 1) that your column headings will be sorted along with the rest of the ps output, likely ending up somewhere you didn't expect to see them and 2) that you need to add an "n" to your sort command when the sort needs to be numerical. You can also pipe the output of the ps aux command to the sort command and select the column to use for sorting by using the column number (1 through 11). Here's a list of the column names and strings that you can use to sort by them: Column Ascending Descending If you only want to see select columns of the ps output, you can specify them as in this example where only commands and their CPU usages are shown and the output is sorted by the largest CPU usage. In this example "pmem" means the percentage of memory usage and using "-pmem" means we'll see the processes using the most memory first. To sort by some other column, you need to use its column name. The command shown below sorts by process ID showing the largest first. Think of - as meaning descending values (largest first) and just the name (e.g., pid) or the name with a plus sign prepended (e.g., +pid) as meaning ascending. ![]() Notice how the display in this case will then start with the highest process ID. To see the largest values for the selected column listed first, you would have to change the sort option (e.g., -pid in place of pid). ![]() However, you can change "pid" to any other column and sort by that one instead. Notice that you need to enter "pid" in lower case. Using the -sort option, you will get the same output if you sort by PID. USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |