190 likes | 322 Views
Process Relationships. all processes have parent processes parent’s are notified of child termination can obtain exit status all processes belong to ‘process groups’ all process groups belong to ‘sessions’ POSIX .1 introduced ‘sessions’ concept. Terminal Logins.
E N D
Process Relationships • all processes have parent processes • parent’s are notified of child termination • can obtain exit status • all processes belong to ‘process groups’ • all process groups belong to ‘sessions’ • POSIX .1 introduced ‘sessions’ concept
Terminal Logins • classic UNIX access provided by dumb terminals • monitor, keyboard and local line or modem connection • contemporary access uses the terminal metaphor • pseudo-terminals provided for network access
4.3 BSD Terminal Logins • terminal logins involve opening terminal or pseudo-terminal devices and exec’ing the login program • login program takes user ID, prompts for password, and then establishes parameters of the working session • last step is for login to exec our ‘login shell’
SVR4 Terminal Logins • SVR4 logins are handled as per BSD, with the addition of ttymon logins. • ttymon logins have a different call structure, but function as per BSD logins from the exec of the login program forward
Network Logins • network logins use the same terminal metaphor that physical terminal logins employ • from the call to login forward, local terminal logins and network logins are essentially similar
BSD and SVR4 Network Logins • network logins take place via a TCP/IP connection request, at which point a specific server establishes a two-way communication and opens a pseudo-terminal • telnet – telnetd handles terminal access • ssh – sshd handles terminal access • both BSD and SVR4 use the same basic logic for terminal access, though the call structures vary
Common login Features • all logins evaluate user data from password, group, etc. and establish working environments • all logins complete by exec’ing a shell process (login shell), and finish when that shell exits
Process Groups • all processes belong to a process group • processes default to the process group of their parent or exec’er • process group ID’s are positive integers • process groups may have a ‘leader’ • PGID = PID for leader • processes can join other groups in same session • must not be group leader
PGID functions • two function used to manipulate process groups • getpgrp() – fetches process group of caller • setpgid() – places a process in an existing group or creates a new one • can be done for calling process or children
Sessions • collection of one or more process groups • processes are usually grouped via a pipeline • created by calling setsid()
setsid() function • setsid() does three things • caller made session leader of new session • caller made group leader of new group • process is made to have no controlling terminal, if one existed prior to the call • caller must not be a process group leader
Controlling Terminal • each session can have only one controlling terminal, and a terminal controls at most one session • the session leader connected to the controlling terminal is the controlling process • session leaders allocate controlling terminals for their sessions via ioctl calls • process groups in a session with a controlling terminal are either foreground or background • one foreground group • terminal signals go to this group • one or more background groups
tcgetpgrp() and tcsetpgrp() Functions • tcgetpgrp() returns foreground group associated with a particular file descriptor • tcsetpgrp() sets the foreground process group • can be used by process with a controlling terminal to change the foreground group to one from another group within the same session
Job Control • BSD feature from early ’80’s • controls multiple foreground and background processes • shells with job control can assign processes to foreground or background • foreground processes receive terminal input, background do not • standard terminal signals are sent to the foreground group
Job Controll Shell Execution of Programs • programs executed within job control shells are assigned to the foreground group by default • if assigned to the background group, programs will stop if need to read from terminal • output to terminal may be allowed or disallowed • user will be notified at next prompt • background process can be moved to foreground
Orphaned Process Groups • a process group is orphaned when no parent processes exist outside the group but in the session. • terminal signals are not sent to the processes in orphaned groups • any stopped process in an orphaned group is automatically sent the the SIGHUP and SIGCONT signals when the group is orphaned.