1 00:00:07,100 --> 00:00:11,600 So the next little piece of it that I want to look at is process groups and 2 00:00:11,600 --> 00:00:15,700 sessions and process groups in sessions, are what we use to 3 00:00:15,700 --> 00:00:19,800 group together sets of processes that are related in one 4 00:00:19,800 --> 00:00:23,500 way or another. Okay. So accession is a structured 5 00:00:24,000 --> 00:00:28,200 that is used to describe a whole collection of processes. 6 00:00:29,000 --> 00:00:33,700 And as we'll see, you have a session leader, and a controlling terminal, and typically its 7 00:00:33,700 --> 00:00:36,100 associated with some login name. And there's 8 00:00:36,400 --> 00:00:40,700 References to it and an identifier so that you have some way of talking about 9 00:00:40,700 --> 00:00:44,700 it. Process groups are used to collect together a 10 00:00:44,700 --> 00:00:48,900 set of processes typically within a session. So a process group is sort of 11 00:00:48,900 --> 00:00:52,700 a subset of a set of processes within a session 12 00:00:52,700 --> 00:00:56,300 and the idea of a process group is usually to identify 13 00:00:56,300 --> 00:01:00,900 tightly related type of processes. So if you have a set of processes that are 14 00:01:00,900 --> 00:01:04,800 in a pipeline, so a pipe to be pipe to see pipe to more. Those 15 00:01:04,800 --> 00:01:05,700 four processes. 16 00:01:06,200 --> 00:01:10,600 We'd all be put together into a process group. So you could refer to them as a whole. 17 00:01:10,600 --> 00:01:14,900 So, you can, for example, stop the pipeline or start the pipeline. If we didn't have 18 00:01:14,900 --> 00:01:18,900 the process group, you have to say, stop. Eh, stop be stopped. See stop more. And 19 00:01:18,900 --> 00:01:22,600 then when you want to start it, start a start. Be start. See, start more. It's much 20 00:01:22,600 --> 00:01:26,800 easier to just be able to say, oh, start that pipeline process group. Stop 21 00:01:26,800 --> 00:01:30,300 that pipeline process group Etc. The easiest way to 22 00:01:30,300 --> 00:01:34,800 understand sessions and process groups, really is with the picture. And 23 00:01:34,800 --> 00:01:36,000 so this picture shows, 24 00:01:36,200 --> 00:01:40,600 Those sort of how this collection of sessions and process groups would work. 25 00:01:40,600 --> 00:01:44,900 So you can see in this picture that we have at the top, we have session 26 00:01:44,900 --> 00:01:48,500 a, and it has within it just a single process process 9. 27 00:01:48,500 --> 00:01:52,900 And then down below it. We have a much bigger session bigger in the 28 00:01:52,900 --> 00:01:55,900 sense of having more processes in it. And this is 29 00:01:55,900 --> 00:01:59,500 has process 10 at the top and then has a 30 00:01:59,500 --> 00:02:03,600 pipeline of process, 11 12 and 13, which is in process group 31 00:02:03,600 --> 00:02:05,700 11, and it's got processes. 32 00:02:06,200 --> 00:02:10,700 Is 14 and 15 group together and process group 14, and then you can see 33 00:02:10,700 --> 00:02:14,800 that process 13 appears to a maybe forked off a shell or something. And then that 34 00:02:14,800 --> 00:02:18,800 she'll started yet another pipeline. So this 35 00:02:18,800 --> 00:02:22,800 would typically be something that you might see from when somebody has 36 00:02:22,800 --> 00:02:26,900 logged in. So that session a up, their process 9 is probably 37 00:02:26,900 --> 00:02:30,300 something like sshd. And so when you first make a 38 00:02:30,300 --> 00:02:34,700 remote, login request you contact sshd on the remote machine 39 00:02:35,300 --> 00:02:36,100 and you 40 00:02:36,200 --> 00:02:40,300 Have an exchange of information to identify yourself. Once the 41 00:02:40,900 --> 00:02:44,900 sshd believes that who you are and what privileges, you ought to have. And 42 00:02:44,900 --> 00:02:48,900 so on and decides that? Yes, in fact, you should be allowed to login. It 43 00:02:48,900 --> 00:02:52,900 is then going to Fork a process, which is going to become your login 44 00:02:52,900 --> 00:02:56,100 shell. And when it first works that process, of course, 45 00:02:56,800 --> 00:03:00,800 it's just going to be part of session a because if you just Fork, you just 46 00:03:00,800 --> 00:03:04,600 stay in the session that you were in previously, but what's going to 47 00:03:04,600 --> 00:03:06,100 happen since it wants to create. 48 00:03:06,200 --> 00:03:10,600 Date a login session for you. It's going to want to have that as an in a whole new 49 00:03:10,600 --> 00:03:14,400 session all by itself. So once process group 10 has been 50 00:03:14,400 --> 00:03:18,800 created, it is going to do the system call set S ID set session 51 00:03:18,800 --> 00:03:22,400 ID, and that is going to take it out of session a and wrap 52 00:03:22,400 --> 00:03:26,700 around it. A new session be and initially, it will be the 53 00:03:26,700 --> 00:03:30,800 only process that's in session be. And because it's the one that 54 00:03:30,800 --> 00:03:34,800 created session B. It is given special status, its can called the 55 00:03:34,800 --> 00:03:36,000 controlling process. 56 00:03:37,000 --> 00:03:41,800 And it is going to be the process that is allowed to manipulate any other processes that 57 00:03:41,800 --> 00:03:43,000 show up in that session. 58 00:03:44,400 --> 00:03:48,800 At that point, then it will probably create, you know, exactly shall so that 59 00:03:48,800 --> 00:03:52,800 it's got a shallow sea shell, SSH, whatever it is that you want. 60 00:03:53,200 --> 00:03:57,900 And now running in the Shell. It's going to Fork off other things. So in 61 00:03:57,900 --> 00:04:01,900 this picture here, you started out the pipeline, which it created is process 62 00:04:01,900 --> 00:04:05,800 group, 11. So created those three processes connected them together with 63 00:04:05,800 --> 00:04:09,600 pipes and then wrap them all together in a 64 00:04:09,600 --> 00:04:12,300 process group of its own process group 11. 65 00:04:12,900 --> 00:04:16,500 And it also went off and did a similar thing with processes, 14 and 15. 66 00:04:16,500 --> 00:04:20,700 And now it has control of everything in that session 67 00:04:20,700 --> 00:04:24,700 and process time is allowed to manipulate anything in that session 68 00:04:24,700 --> 00:04:28,800 that it wants to it. Can decide process group 11 is going to be the foreground 69 00:04:28,800 --> 00:04:32,500 process group and can read and write the keyboard and write to the screen or 70 00:04:32,500 --> 00:04:36,900 it can say, no. No, I don't want you. I want you to stop instead. I want to make 71 00:04:36,900 --> 00:04:40,500 process 14, the process foreground process groups, and now it's allowed to manipulate 72 00:04:40,500 --> 00:04:42,600 things on the screen and read from the keyboard. 73 00:04:43,100 --> 00:04:47,700 You can put things in background so I can say, all right. Well you can run but if you try and read from the 74 00:04:47,700 --> 00:04:51,900 keyboard, you're going to get a stop signal because you know, you're not, you're not the foreground 75 00:04:51,900 --> 00:04:55,700 process group, in short process, group 10 is, is in charge. 76 00:04:55,700 --> 00:04:59,400 And the idea of a session is that it identifies 77 00:04:59,400 --> 00:05:03,300 as a set of processes that process 10, in this case 78 00:05:03,300 --> 00:05:07,900 is allowed to manipulate. So process, 10 can do anything, it wants to anything in 79 00:05:07,900 --> 00:05:11,800 session, be including some things that got forked off like 16 and 80 00:05:11,800 --> 00:05:12,800 process group. 81 00:05:13,000 --> 00:05:17,700 Tune that are far below it, but they are children of one of its children. 82 00:05:17,700 --> 00:05:21,600 So it's allowed to start them and stop them and do other things. 83 00:05:21,600 --> 00:05:25,600 In particular, though. It is not allowed to access 84 00:05:25,600 --> 00:05:29,800 anything that's outside of that session bubble. So it's not allowed to reach over 85 00:05:29,800 --> 00:05:33,800 into session. See and manipulate any of the processes that 86 00:05:33,800 --> 00:05:37,700 are over in that session. So in essence, then the session is what is 87 00:05:37,700 --> 00:05:41,600 protecting us essentially putting a bubble around us for the 88 00:05:41,600 --> 00:05:43,000 purposes of log. 89 00:05:43,000 --> 00:05:47,300 In sessions, and then the process groups are just a way of 90 00:05:47,300 --> 00:05:51,800 accumulating a set of processes together and make it easy for 91 00:05:51,800 --> 00:05:55,700 us to manipulate them as a group rather than having to talk 92 00:05:55,700 --> 00:05:57,400 about them individually.