Advanced Programming in the UNIX® Environment

(lily) #1
ptg10805159

Section 9.11FreeBSD Implementation 311



  • s_leaderis a pointer to theprocstructure of the session leader.

  • s_ttyvpis a pointer to thevnodestructure of the controlling terminal.

  • s_ttypis a pointer to thettystructure of the controlling terminal.

  • s_sidis the session ID. Recall that the concept of a session ID is not part of the
    Single UNIX Specification.


Whensetsidis called, a newsessionstructureisallocated within the kernel.
Nows_countis set to 1,s_leaderis set to point to theprocstructure of the calling
process,s_sidis set to the process ID, ands_ttyvpands_ttypareset to null
pointers, since the new session doesn’t have a controlling terminal.
Let’s move to thettystructure. The kernel contains one of these structures for
each terminal device and each pseudo terminal device. (Wetalk moreabout pseudo
terminals in Chapter 19.)


  • t_sessionpoints to the sessionstructurethat has this terminal as its
    controlling terminal. (Note that the tty structurepoints to the session
    structure, and vice versa.) This pointer is used by the terminal to send a hang-
    up signal to the session leader if the terminal loses carrier (Figure9.7).

  • t_pgrppoints to thepgrpstructureofthe foreground process group. This field
    is used by the terminal driver to send signals to the foreground process group.
    The three signals generated by entering special characters (interrupt, quit, and
    suspend) aresent to the foreground process group.

  • t_termios is a structurecontaining all the special characters and related
    information for this terminal, such as baud rate, whether echo is enabled, and so
    on. We’ll return to this structure in Chapter 18.

  • t_winsizeis awinsizestructurethat contains the current size of the terminal
    window.When the size of the terminal window changes, theSIGWINCHsignal
    is sent to the foreground process group. Weshow how to set and fetch the
    terminal’s current window size in Section 18.12.


To find the foreground process group of a particular session, the kernel has to start with
the session structure, follows_ttypto get to the controlling terminal’sttystructure,
and then followt_pgrpto get to the foreground process group’spgrpstructure. The
pgrpstructurecontains the information for a particular process group.


  • pg_idis the process group ID.

  • pg_sessionpoints to the sessionstructurefor the session to which this
    process group belongs.

  • pg_membersis a pointer to the list ofprocstructures that aremembers of this
    process group. Thep_pgliststructureinthatprocstructure is a doubly
    linked list entry that points to both the next process and the previous process in
    the group, and so on, until a null pointer is encountered in theprocstructureof
    the last process in the group.

Free download pdf