So the next little piece of it that I want to look at is process groups and
sessions and process groups in sessions, are what we use to
group together sets of processes that are related in one
way or another. Okay. So accession is a structured
that is used to describe a whole collection of processes.
And as we'll see, you have a session leader, and a controlling terminal, and typically its
associated with some login name. And there's
References to it and an identifier so that you have some way of talking about
it. Process groups are used to collect together a
set of processes typically within a session. So a process group is sort of
a subset of a set of processes within a session
and the idea of a process group is usually to identify
tightly related type of processes. So if you have a set of processes that are
in a pipeline, so a pipe to be pipe to see pipe to more. Those
four processes.
We'd all be put together into a process group. So you could refer to them as a whole.
So, you can, for example, stop the pipeline or start the pipeline. If we didn't have
the process group, you have to say, stop. Eh, stop be stopped. See stop more. And
then when you want to start it, start a start. Be start. See, start more. It's much
easier to just be able to say, oh, start that pipeline process group. Stop
that pipeline process group Etc. The easiest way to
understand sessions and process groups, really is with the picture. And
so this picture shows,
Those sort of how this collection of sessions and process groups would work.
So you can see in this picture that we have at the top, we have session
a, and it has within it just a single process process 9.
And then down below it. We have a much bigger session bigger in the
sense of having more processes in it. And this is
has process 10 at the top and then has a
pipeline of process, 11 12 and 13, which is in process group
11, and it's got processes.
Is 14 and 15 group together and process group 14, and then you can see
that process 13 appears to a maybe forked off a shell or something. And then that
she'll started yet another pipeline. So this
would typically be something that you might see from when somebody has
logged in. So that session a up, their process 9 is probably
something like sshd. And so when you first make a
remote, login request you contact sshd on the remote machine
and you
Have an exchange of information to identify yourself. Once the
sshd believes that who you are and what privileges, you ought to have. And
so on and decides that? Yes, in fact, you should be allowed to login. It
is then going to Fork a process, which is going to become your login
shell. And when it first works that process, of course,
it's just going to be part of session a because if you just Fork, you just
stay in the session that you were in previously, but what's going to
happen since it wants to create.
Date a login session for you. It's going to want to have that as an in a whole new
session all by itself. So once process group 10 has been
created, it is going to do the system call set S ID set session
ID, and that is going to take it out of session a and wrap
around it. A new session be and initially, it will be the
only process that's in session be. And because it's the one that
created session B. It is given special status, its can called the
controlling process.
And it is going to be the process that is allowed to manipulate any other processes that
show up in that session.
At that point, then it will probably create, you know, exactly shall so that
it's got a shallow sea shell, SSH, whatever it is that you want.
And now running in the Shell. It's going to Fork off other things. So in
this picture here, you started out the pipeline, which it created is process
group, 11. So created those three processes connected them together with
pipes and then wrap them all together in a
process group of its own process group 11.
And it also went off and did a similar thing with processes, 14 and 15.
And now it has control of everything in that session
and process time is allowed to manipulate anything in that session
that it wants to it. Can decide process group 11 is going to be the foreground
process group and can read and write the keyboard and write to the screen or
it can say, no. No, I don't want you. I want you to stop instead. I want to make
process 14, the process foreground process groups, and now it's allowed to manipulate
things on the screen and read from the keyboard.
You can put things in background so I can say, all right. Well you can run but if you try and read from the
keyboard, you're going to get a stop signal because you know, you're not, you're not the foreground
process group, in short process, group 10 is, is in charge.
And the idea of a session is that it identifies
as a set of processes that process 10, in this case
is allowed to manipulate. So process, 10 can do anything, it wants to anything in
session, be including some things that got forked off like 16 and
process group.
Tune that are far below it, but they are children of one of its children.
So it's allowed to start them and stop them and do other things.
In particular, though. It is not allowed to access
anything that's outside of that session bubble. So it's not allowed to reach over
into session. See and manipulate any of the processes that
are over in that session. So in essence, then the session is what is
protecting us essentially putting a bubble around us for the
purposes of log.
In sessions, and then the process groups are just a way of
accumulating a set of processes together and make it easy for
us to manipulate them as a group rather than having to talk
about them individually.