6 When the system is bootstrapped the kernel creates process ID 1, the init
7 process, and it is init that brings the system up multiuser. init reads its
8 configuration file (/etc/inittab) and, for every terminal device that allows
9 a login, init does a fork followed by an exec of the program getty. init does
10 the exec of getty with an empty environment.
12 It's getty that calls open for the terminal device. The terminal is open for
13 read and writting. Once the device is open, file descriptors 0, 1 and 2 are
14 set to the device. Then getty outputs something like 'login:' and waits for
15 us to enter our user name.
17 getty is done when we enter our user name, It then invokes the login
20 execle("/usr/bin/login", "login", "-p", username, (char *) 0, envp)
22 getty creates an environment for login (the 'envp' argument) with the
23 name of the terminal (something like TERM=foo) and any environment
24 strings that are specified in the gettytab. The -p flag to login tells
25 it to preserve the environment that it is passed and to add to that
26 environment, not replace it.
28 All the started process have superuser privileges.
30 Now login does many things. It calls getpass(3) to display the prompt
31 'Password:' and read our password. After a long validation process,
32 login changes to our home directory (chdir). The ownership of our
33 terminal devices is changed (chown) so we are the owner and group
34 owner. The access permissions are also changed for the terminal device,
35 so that user-read, user-write, and group-write are enabled. Our group
36 IDs are set, by calling setgid and then initgroups. The environment is
37 then initilized with all the information that login has: our home
38 directory (HOME), shell (SHELL), user name (USER and LOGNAME), and a
39 default (PATH). Finally it changes to our user ID (setuid) and invokes
40 our login shell, as in
42 execl("/bin/sh", "-sh", (char *) 0);
44 The minus sign as the first character of argv[0] is a flag to all the
45 shells that they are being invoked as a login shell. The shells can look
46 at this character and modify their start-up accordingly.
50 A process group is a collection of one or more processes. Each process
51 group has a unique process group ID.
53 Each process group can have a process group leader. The leader is
54 identified by having its process group ID equal its process ID.
56 See setpgid() to set a new (or join in a) process group.
60 A session is a collection of one or more process groups.
62 A process establishes a new session by calling the setsid() function.
64 *) Controlling Terminal
66 There are a few other characteristics of sessions and process groups.
68 - A session can have a single _controlling terminal_. This is usually
69 the terminal device or pseudo-terminal device on which we log in.
71 - The session leader that establishes the connection to the controlling
72 terminal is called the _controlling process_.
74 - The process groups within a session can be divided into a single
75 'foreground process group' and one or more 'background process groups'.
77 - If a session has a controlling terminal, then it has a single foreground
78 process group, and all other process groups in the session are
79 background process groups.
81 - Whenever we type our terminal's interrupt key (Control-C) or quit key
82 (Control-XXX) this causes the interrupt signal or the quit signal to be
83 sent to all processes in the foreground process group.
85 see tcsetpgrp() to set and get terminal foregroup process group.