1 00:00:06,559 --> 00:00:12,905 While working with processes. This is useful if you know how to show process properties and the PS command is what 2 00:00:12,905 --> 00:00:19,250 you use to do. So we have already seen it occasionally. Now let's talk about the different options that it has. 3 00:00:20,030 --> 00:00:25,384 So PS is the main command to show running processes. From the command line you can 4 00:00:25,384 --> 00:00:30,739 use PS aux to to show all processes, including the most useful information about these processes. 5 00:00:31,320 --> 00:00:35,320 Or psfax, which shows parent child relations between processes. 6 00:00:36,659 --> 00:00:41,459 PS has many options, so use any options that you want to get 7 00:00:41,459 --> 00:00:46,259 your process information. You'll find more information in the man pages about it. 8 00:00:48,079 --> 00:00:54,009 Now, as a tip, I should suggest that you consider piping PS output to other tools 9 00:00:54,009 --> 00:00:59,939 like AWK and Sort and Cut to find the information about processes that you want. 10 00:01:00,700 --> 00:01:02,079 Let's do a quick PS primer. 11 00:01:03,259 --> 00:01:08,090 So I'm going to start with psaox. That's all my processes in the order 12 00:01:08,090 --> 00:01:12,920 of pid, where the process that was started last will be listed last. 13 00:01:13,560 --> 00:01:17,379 Now if I would use psaox pipe grep, then I 14 00:01:17,379 --> 00:01:21,199 can filter on processes. We talked about this before. 15 00:01:22,000 --> 00:01:25,579 In the result you can see the SSH process but also the grep command. 16 00:01:26,269 --> 00:01:33,069 And if you don't like that very much, add grep v grep behind it so that you only see the process itself. 17 00:01:34,489 --> 00:01:39,450 Now, PSAOx is one way of using PS. In fact, there's a funny story behind it. 18 00:01:40,290 --> 00:01:44,349 Normally in Linux, command line options have a hyphen in front of them. 19 00:01:45,010 --> 00:01:50,189 But in the history of Linux, back in the days of Unix, there were two main dialects. 20 00:01:50,700 --> 00:01:53,780 In the BSD dialects, options could be used without hyphen. 21 00:01:54,340 --> 00:01:57,900 In the System V dialect, options could be used with a hyphen. 22 00:01:58,420 --> 00:02:04,943 NPS happens to be a BSD background. And because of that BSD background that was ported to Linux, you 23 00:02:04,943 --> 00:02:11,466 can still use it either BSD way or System five way. And that means either with or without a 24 00:02:11,466 --> 00:02:17,990 hyphen. And that is why psaux as well as PS AUX are both showing the same information. 25 00:02:18,710 --> 00:02:23,585 You can also use PS E F, which is more a System 5 way 26 00:02:23,585 --> 00:02:28,460 of doing it, and that is showing also a lot of information about processes. 27 00:02:29,300 --> 00:02:35,884 Probably quite important to know is what exactly you see and you will find out if you pipe the 28 00:02:35,884 --> 00:02:42,469 output of PSAOx to less there on the top row you can see everything that is displayed. So the 29 00:02:42,469 --> 00:02:49,055 username, the process identifier, the CPU usage, the memory usage, virtual memory that is used and resident memory that 30 00:02:49,055 --> 00:02:55,639 is used in kilobytes. And the resident memory is what really matters. Virtual memory is not so very important. 31 00:02:56,639 --> 00:03:03,310 Skipping a few columns. Then we have the start time, when it was started, the amount of time it is used, 32 00:03:03,310 --> 00:03:09,980 and the command itself. Now another command that I like a lot is psfaux that will show you a process forest. 33 00:03:10,860 --> 00:03:15,719 And this forest is relevant because in processes there is always a parent child relation. 34 00:03:16,300 --> 00:03:21,564 So here you can see that the psfaux command was started from a bash 35 00:03:21,564 --> 00:03:26,829 shell and this bash shel is a part of the pty XIS command. 36 00:03:27,490 --> 00:03:34,330 And using this parent child relationship might be convenient to figure out what exactly is going on. 37 00:03:35,090 --> 00:03:41,893 Now you can also use PS with options that are quite advanced like 38 00:03:41,893 --> 00:03:48,696 PS E o pid arcs minus forest which is showing options. And in 39 00:03:48,696 --> 00:03:55,500 the options we have the process ID and we have the forest option. 40 00:03:56,520 --> 00:03:58,699 Or what do you think of ps? 41 00:03:59,719 --> 00:04:05,489 C SSHD L O PID 42 00:04:05,489 --> 00:04:11,259 TID PCPU stage NLWPNRCS Wow, 43 00:04:11,259 --> 00:04:17,029 that's a lot of options. 44 00:04:17,589 --> 00:04:21,289 And what do we see in this output? Well, we see threads. If 45 00:04:21,289 --> 00:04:24,990 you have a multi threaded process, you can go as deep as this. 46 00:04:25,529 --> 00:04:30,875 I'm not expecting you to remember stuff like this, but I'm expecting you to know that 47 00:04:30,875 --> 00:04:36,220 in PS there's a lot of options that allows you to filter information about specific processes. 48 00:04:37,800 --> 00:04:42,360 Also a nice one is psaox sort PMEM 49 00:04:42,360 --> 00:04:46,920 that will sort your processes by memory. 50 00:04:47,970 --> 00:04:49,209 Let's filter it to less. 51 00:04:49,769 --> 00:04:56,560 And there you get an overview of the memory usage. Lowest is first, so the bottom lines 52 00:04:56,560 --> 00:05:03,350 are most interesting there you can see in the fourth column that gnome shell, apparently with 9.5% 53 00:05:03,349 --> 00:05:10,139 memory, is the process that uses most of memory. And that's how you can use.