home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume25 / pty4 / part09 < prev    next >
SHell self-extracting ARchive  |  1992-02-18  |  26.0 KB

open in: MacOS 8.1     |     Win98     |     DOS

browse contents    |     view JSON data     |     view as text


This file was processed as: SHell self-extracting ARchive (archive/shar).

ConfidenceProgramDetectionMatch TypeSupport
100% dexvert SHell self-extracting ARchive (archive/shar) magic Supported
1% dexvert Text File (text/txt) fallback Supported
100% file ASCII text default
100% checkBytes Printable ASCII default
100% perlTextCheck Likely Text (Perl) default
100% siegfried fmt/329 Shell Archive Format default
100% detectItEasy Format: plain text[LF] default (weak)



hex view
+--------+-------------------------+-------------------------+--------+--------+
|00000000| 4e 65 77 73 67 72 6f 75 | 70 73 3a 20 63 6f 6d 70 |Newsgrou|ps: comp|
|00000010| 2e 73 6f 75 72 63 65 73 | 2e 75 6e 69 78 0a 46 72 |.sources|.unix.Fr|
|00000020| 6f 6d 3a 20 62 72 6e 73 | 74 6e 64 40 6e 79 75 2e |om: brns|tnd@nyu.|
|00000030| 65 64 75 20 28 44 61 6e | 20 42 65 72 6e 73 74 65 |edu (Dan| Bernste|
|00000040| 69 6e 29 0a 53 75 62 6a | 65 63 74 3a 20 76 32 35 |in).Subj|ect: v25|
|00000050| 69 31 33 35 3a 20 47 65 | 6e 65 72 61 6c 69 7a 65 |i135: Ge|neralize|
|00000060| 64 20 69 6e 74 65 72 66 | 61 63 65 20 74 6f 20 70 |d interf|ace to p|
|00000070| 73 65 75 64 6f 2d 74 74 | 79 20 64 65 76 69 63 65 |seudo-tt|y device|
|00000080| 73 2c 20 50 61 72 74 30 | 39 2f 30 39 0a 53 65 6e |s, Part0|9/09.Sen|
|00000090| 64 65 72 3a 20 75 6e 69 | 78 2d 73 6f 75 72 63 65 |der: uni|x-source|
|000000a0| 73 2d 6d 6f 64 65 72 61 | 74 6f 72 40 70 61 2e 64 |s-modera|tor@pa.d|
|000000b0| 65 63 2e 63 6f 6d 0a 41 | 70 70 72 6f 76 65 64 3a |ec.com.A|pproved:|
|000000c0| 20 76 69 78 69 65 40 70 | 61 2e 64 65 63 2e 63 6f | vixie@p|a.dec.co|
|000000d0| 6d 0a 0a 53 75 62 6d 69 | 74 74 65 64 2d 42 79 3a |m..Submi|tted-By:|
|000000e0| 20 62 72 6e 73 74 6e 64 | 40 6e 79 75 2e 65 64 75 | brnstnd|@nyu.edu|
|000000f0| 20 28 44 61 6e 20 42 65 | 72 6e 73 74 65 69 6e 29 | (Dan Be|rnstein)|
|00000100| 0a 50 6f 73 74 69 6e 67 | 2d 4e 75 6d 62 65 72 3a |.Posting|-Number:|
|00000110| 20 56 6f 6c 75 6d 65 20 | 32 35 2c 20 49 73 73 75 | Volume |25, Issu|
|00000120| 65 20 31 33 35 0a 41 72 | 63 68 69 76 65 2d 4e 61 |e 135.Ar|chive-Na|
|00000130| 6d 65 3a 20 70 74 79 34 | 2f 70 61 72 74 30 39 0a |me: pty4|/part09.|
|00000140| 0a 23 21 20 2f 62 69 6e | 2f 73 68 0a 23 20 54 68 |.#! /bin|/sh.# Th|
|00000150| 69 73 20 69 73 20 61 20 | 73 68 65 6c 6c 20 61 72 |is is a |shell ar|
|00000160| 63 68 69 76 65 2e 20 20 | 52 65 6d 6f 76 65 20 61 |chive. |Remove a|
|00000170| 6e 79 74 68 69 6e 67 20 | 62 65 66 6f 72 65 20 74 |nything |before t|
|00000180| 68 69 73 20 6c 69 6e 65 | 2c 20 74 68 65 6e 20 75 |his line|, then u|
|00000190| 6e 70 61 63 6b 0a 23 20 | 69 74 20 62 79 20 73 61 |npack.# |it by sa|
|000001a0| 76 69 6e 67 20 69 74 20 | 69 6e 74 6f 20 61 20 66 |ving it |into a f|
|000001b0| 69 6c 65 20 61 6e 64 20 | 74 79 70 69 6e 67 20 22 |ile and |typing "|
|000001c0| 73 68 20 66 69 6c 65 22 | 2e 20 20 54 6f 20 6f 76 |sh file"|. To ov|
|000001d0| 65 72 77 72 69 74 65 20 | 65 78 69 73 74 69 6e 67 |erwrite |existing|
|000001e0| 0a 23 20 66 69 6c 65 73 | 2c 20 74 79 70 65 20 22 |.# files|, type "|
|000001f0| 73 68 20 66 69 6c 65 20 | 2d 63 22 2e 20 20 59 6f |sh file |-c". Yo|
|00000200| 75 20 63 61 6e 20 61 6c | 73 6f 20 66 65 65 64 20 |u can al|so feed |
|00000210| 74 68 69 73 20 61 73 20 | 73 74 61 6e 64 61 72 64 |this as |standard|
|00000220| 20 69 6e 70 75 74 20 76 | 69 61 0a 23 20 75 6e 73 | input v|ia.# uns|
|00000230| 68 61 72 2c 20 6f 72 20 | 62 79 20 74 79 70 69 6e |har, or |by typin|
|00000240| 67 20 22 73 68 20 3c 66 | 69 6c 65 22 2c 20 65 2e |g "sh <f|ile", e.|
|00000250| 67 2e 2e 20 20 49 66 20 | 74 68 69 73 20 61 72 63 |g.. If |this arc|
|00000260| 68 69 76 65 20 69 73 20 | 63 6f 6d 70 6c 65 74 65 |hive is |complete|
|00000270| 2c 20 79 6f 75 0a 23 20 | 77 69 6c 6c 20 73 65 65 |, you.# |will see|
|00000280| 20 74 68 65 20 66 6f 6c | 6c 6f 77 69 6e 67 20 6d | the fol|lowing m|
|00000290| 65 73 73 61 67 65 20 61 | 74 20 74 68 65 20 65 6e |essage a|t the en|
|000002a0| 64 3a 0a 23 09 09 22 45 | 6e 64 20 6f 66 20 61 72 |d:.#.."E|nd of ar|
|000002b0| 63 68 69 76 65 20 39 20 | 28 6f 66 20 39 29 2e 22 |chive 9 |(of 9)."|
|000002c0| 0a 23 20 43 6f 6e 74 65 | 6e 74 73 3a 20 20 4a 4f |.# Conte|nts: JO|
|000002d0| 42 43 54 52 4c 2e 64 72 | 61 66 74 33 0a 23 20 57 |BCTRL.dr|aft3.# W|
|000002e0| 72 61 70 70 65 64 20 62 | 79 20 76 69 78 69 65 40 |rapped b|y vixie@|
|000002f0| 63 6f 67 6e 69 74 69 6f | 6e 2e 70 61 2e 64 65 63 |cognitio|n.pa.dec|
|00000300| 2e 63 6f 6d 20 6f 6e 20 | 57 65 64 20 46 65 62 20 |.com on |Wed Feb |
|00000310| 31 39 20 31 33 3a 33 35 | 3a 30 37 20 31 39 39 32 |19 13:35|:07 1992|
|00000320| 0a 50 41 54 48 3d 2f 62 | 69 6e 3a 2f 75 73 72 2f |.PATH=/b|in:/usr/|
|00000330| 62 69 6e 3a 2f 75 73 72 | 2f 75 63 62 20 3b 20 65 |bin:/usr|/ucb ; e|
|00000340| 78 70 6f 72 74 20 50 41 | 54 48 0a 69 66 20 74 65 |xport PA|TH.if te|
|00000350| 73 74 20 2d 66 20 27 4a | 4f 42 43 54 52 4c 2e 64 |st -f 'J|OBCTRL.d|
|00000360| 72 61 66 74 33 27 20 2d | 61 20 22 24 7b 31 7d 22 |raft3' -|a "${1}"|
|00000370| 20 21 3d 20 22 2d 63 22 | 20 3b 20 74 68 65 6e 20 | != "-c"| ; then |
|00000380| 0a 20 20 65 63 68 6f 20 | 73 68 61 72 3a 20 57 69 |. echo |shar: Wi|
|00000390| 6c 6c 20 6e 6f 74 20 63 | 6c 6f 62 62 65 72 20 65 |ll not c|lobber e|
|000003a0| 78 69 73 74 69 6e 67 20 | 66 69 6c 65 20 5c 22 27 |xisting |file \"'|
|000003b0| 4a 4f 42 43 54 52 4c 2e | 64 72 61 66 74 33 27 5c |JOBCTRL.|draft3'\|
|000003c0| 22 0a 65 6c 73 65 0a 65 | 63 68 6f 20 73 68 61 72 |".else.e|cho shar|
|000003d0| 3a 20 45 78 74 72 61 63 | 74 69 6e 67 20 5c 22 27 |: Extrac|ting \"'|
|000003e0| 4a 4f 42 43 54 52 4c 2e | 64 72 61 66 74 33 27 5c |JOBCTRL.|draft3'\|
|000003f0| 22 20 5c 28 32 34 38 32 | 33 20 63 68 61 72 61 63 |" \(2482|3 charac|
|00000400| 74 65 72 73 5c 29 0a 73 | 65 64 20 22 73 2f 5e 58 |ters\).s|ed "s/^X|
|00000410| 2f 2f 22 20 3e 27 4a 4f | 42 43 54 52 4c 2e 64 72 |//" >'JO|BCTRL.dr|
|00000420| 61 66 74 33 27 20 3c 3c | 27 45 4e 44 5f 4f 46 5f |aft3' <<|'END_OF_|
|00000430| 46 49 4c 45 27 0a 48 6f | 77 20 74 6f 20 61 64 64 |FILE'.Ho|w to add|
|00000440| 20 6a 6f 62 20 63 6f 6e | 74 72 6f 6c 20 74 6f 20 | job con|trol to |
|00000450| 61 20 55 4e 49 58 20 73 | 79 73 74 65 6d 0a 44 61 |a UNIX s|ystem.Da|
|00000460| 6e 69 65 6c 20 4a 2e 20 | 42 65 72 6e 73 74 65 69 |niel J. |Bernstei|
|00000470| 6e 0a 64 72 61 66 74 20 | 33 0a 58 38 2f 33 2f 39 |n.draft |3.X8/3/9|
|00000480| 31 0a 58 0a 58 0a 41 62 | 73 74 72 61 63 74 0a 58 |1.X.X.Ab|stract.X|
|00000490| 0a 57 65 20 64 65 73 63 | 72 69 62 65 20 69 6e 20 |.We desc|ribe in |
|000004a0| 64 65 74 61 69 6c 20 74 | 68 65 20 73 74 65 70 73 |detail t|he steps|
|000004b0| 20 6e 65 63 65 73 73 61 | 72 79 20 74 6f 20 61 64 | necessa|ry to ad|
|000004c0| 64 20 42 53 44 2d 73 74 | 79 6c 65 20 6a 6f 62 20 |d BSD-st|yle job |
|000004d0| 63 6f 6e 74 72 6f 6c 0a | 74 6f 20 61 6e 79 20 55 |control.|to any U|
|000004e0| 4e 49 58 20 73 79 73 74 | 65 6d 2e 20 49 6e 20 70 |NIX syst|em. In p|
|000004f0| 6c 61 63 65 20 6f 66 20 | 74 68 65 20 42 53 44 20 |lace of |the BSD |
|00000500| 61 6e 64 20 50 4f 53 49 | 58 20 72 75 6c 65 73 20 |and POSI|X rules |
|00000510| 66 6f 72 20 63 6f 6e 74 | 72 6f 6c 6c 69 6e 67 0a |for cont|rolling.|
|00000520| 74 74 79 73 2c 20 73 65 | 73 73 69 6f 6e 73 2c 20 |ttys, se|ssions, |
|00000530| 61 6e 64 20 70 72 6f 63 | 65 73 73 20 67 72 6f 75 |and proc|ess grou|
|00000540| 70 73 2c 20 77 65 20 70 | 72 6f 70 6f 73 65 20 61 |ps, we p|ropose a|
|00000550| 20 76 65 72 79 20 73 69 | 6d 70 6c 65 20 79 65 74 | very si|mple yet|
|00000560| 20 73 65 63 75 72 65 0a | 6d 65 63 68 61 6e 69 73 | secure.|mechanis|
|00000570| 6d 20 66 6f 72 20 6d 61 | 6e 69 70 75 6c 61 74 69 |m for ma|nipulati|
|00000580| 6e 67 20 70 72 6f 63 65 | 73 73 20 67 72 6f 75 70 |ng proce|ss group|
|00000590| 73 20 61 6c 6f 6e 65 2e | 20 54 68 69 73 20 6d 65 |s alone.| This me|
|000005a0| 63 68 61 6e 69 73 6d 20 | 63 61 6e 20 61 6c 73 6f |chanism |can also|
|000005b0| 0a 62 65 20 61 64 64 65 | 64 20 74 6f 20 65 78 69 |.be adde|d to exi|
|000005c0| 73 74 69 6e 67 20 42 53 | 44 20 73 79 73 74 65 6d |sting BS|D system|
|000005d0| 73 20 74 6f 20 70 72 6f | 76 69 64 65 20 61 6e 20 |s to pro|vide an |
|000005e0| 61 6c 74 65 72 6e 61 74 | 65 2c 20 65 61 73 69 65 |alternat|e, easie|
|000005f0| 72 2d 74 6f 2d 75 73 65 | 0a 70 72 6f 67 72 61 6d |r-to-use|.program|
|00000600| 6d 69 6e 67 20 69 6e 74 | 65 72 66 61 63 65 2e 0a |ming int|erface..|
|00000610| 58 0a 58 0a 58 31 2e 20 | 49 6e 74 72 6f 64 75 63 |X.X.X1. |Introduc|
|00000620| 74 69 6f 6e 0a 58 0a 53 | 65 63 74 69 6f 6e 73 20 |tion.X.S|ections |
|00000630| 32 20 74 68 72 6f 75 67 | 68 20 36 20 64 65 73 63 |2 throug|h 6 desc|
|00000640| 72 69 62 65 20 73 65 6c | 65 63 74 65 64 20 70 6f |ribe sel|ected po|
|00000650| 72 74 69 6f 6e 73 20 6f | 66 20 42 53 44 20 34 2e |rtions o|f BSD 4.|
|00000660| 32 20 61 6e 64 20 34 2e | 33 20 6a 6f 62 0a 63 6f |2 and 4.|3 job.co|
|00000670| 6e 74 72 6f 6c 2e 20 4f | 6d 69 74 74 65 64 20 69 |ntrol. O|mitted i|
|00000680| 73 20 61 6e 79 20 6d 65 | 6e 74 69 6f 6e 20 6f 66 |s any me|ntion of|
|00000690| 20 63 6f 6e 74 72 6f 6c | 6c 69 6e 67 20 74 74 79 | control|ling tty|
|000006a0| 73 2c 20 50 4f 53 49 58 | 20 73 65 73 73 69 6f 6e |s, POSIX| session|
|000006b0| 73 2c 0a 67 65 74 70 67 | 72 70 28 29 20 61 6e 64 |s,.getpg|rp() and|
|000006c0| 20 73 65 74 70 67 72 70 | 28 29 2c 20 54 49 4f 43 | setpgrp|(), TIOC|
|000006d0| 47 50 47 52 50 20 61 6e | 64 20 54 49 4f 43 53 50 |GPGRP an|d TIOCSP|
|000006e0| 47 52 50 2c 20 74 63 67 | 65 74 70 67 72 70 28 29 |GRP, tcg|etpgrp()|
|000006f0| 20 61 6e 64 0a 74 63 73 | 65 74 70 67 72 70 28 29 | and.tcs|etpgrp()|
|00000700| 2c 20 54 49 4f 43 4e 4f | 54 54 59 2c 20 73 65 74 |, TIOCNO|TTY, set|
|00000710| 73 69 64 28 29 2c 20 54 | 49 4f 43 53 43 54 54 59 |sid(), T|IOCSCTTY|
|00000720| 2c 20 73 65 74 70 67 69 | 64 28 29 2c 20 6f 70 65 |, setpgi|d(), ope|
|00000730| 6e 28 29 20 77 69 74 68 | 20 6f 72 0a 77 69 74 68 |n() with| or.with|
|00000740| 6f 75 74 20 4f 5f 4e 4f | 43 54 54 59 2c 20 61 6e |out O_NO|CTTY, an|
|00000750| 64 20 74 68 65 20 72 65 | 6c 61 74 69 6f 6e 73 20 |d the re|lations |
|00000760| 62 65 74 77 65 65 6e 20 | 61 6c 6c 20 6f 66 20 74 |between |all of t|
|00000770| 68 6f 73 65 20 61 6e 64 | 20 74 68 65 20 72 65 73 |hose and| the res|
|00000780| 74 20 6f 66 0a 74 68 65 | 20 6a 6f 62 20 63 6f 6e |t of.the| job con|
|00000790| 74 72 6f 6c 20 73 79 73 | 74 65 6d 2c 20 62 65 63 |trol sys|tem, bec|
|000007a0| 61 75 73 65 20 69 74 20 | 74 75 72 6e 73 20 6f 75 |ause it |turns ou|
|000007b0| 74 20 74 68 61 74 20 6e | 6f 6e 65 20 6f 66 20 74 |t that n|one of t|
|000007c0| 68 61 74 20 69 73 0a 6e | 65 63 65 73 73 61 72 79 |hat is.n|ecessary|
|000007d0| 20 74 6f 20 70 72 6f 76 | 69 64 65 20 6a 6f 62 20 | to prov|ide job |
|000007e0| 63 6f 6e 74 72 6f 6c 2e | 20 54 68 65 20 61 74 74 |control.| The att|
|000007f0| 69 74 75 64 65 20 69 6e | 20 74 68 65 73 65 20 73 |itude in| these s|
|00000800| 65 63 74 69 6f 6e 73 20 | 69 73 20 74 68 61 74 0a |ections |is that.|
|00000810| 6f 66 20 73 6f 6d 65 6f | 6e 65 20 66 61 63 65 64 |of someo|ne faced|
|00000820| 20 77 69 74 68 20 61 20 | 53 79 73 74 65 6d 20 56 | with a |System V|
|00000830| 20 76 61 72 69 61 6e 74 | 20 6f 72 20 61 20 6e 65 | variant| or a ne|
|00000840| 77 20 55 4e 49 58 20 73 | 79 73 74 65 6d 20 28 65 |w UNIX s|ystem (e|
|00000850| 2e 67 2e 2c 0a 4d 49 4e | 49 58 29 20 77 69 74 68 |.g.,.MIN|IX) with|
|00000860| 20 6e 6f 20 6a 6f 62 20 | 63 6f 6e 74 72 6f 6c 20 | no job |control |
|00000870| 66 61 63 69 6c 69 74 69 | 65 73 20 69 6e 20 74 68 |faciliti|es in th|
|00000880| 65 20 66 69 72 73 74 20 | 70 6c 61 63 65 2c 20 70 |e first |place, p|
|00000890| 65 72 68 61 70 73 0a 77 | 69 74 68 6f 75 74 20 65 |erhaps.w|ithout e|
|000008a0| 76 65 6e 20 74 68 65 20 | 63 6f 6e 63 65 70 74 20 |ven the |concept |
|000008b0| 6f 66 20 61 20 63 6f 6e | 74 72 6f 6c 6c 69 6e 67 |of a con|trolling|
|000008c0| 20 74 74 79 3b 20 74 68 | 65 20 69 6d 70 6f 72 74 | tty; th|e import|
|000008d0| 61 6e 74 20 71 75 65 73 | 74 69 6f 6e 20 69 73 0a |ant ques|tion is.|
|000008e0| 68 6f 77 20 6c 69 74 74 | 6c 65 20 77 6f 72 6b 20 |how litt|le work |
|000008f0| 69 73 20 6e 65 63 65 73 | 73 61 72 79 20 74 6f 20 |is neces|sary to |
|00000900| 61 64 64 20 6a 6f 62 20 | 63 6f 6e 74 72 6f 6c 20 |add job |control |
|00000910| 66 65 61 74 75 72 65 73 | 2e 0a 58 0a 53 65 63 74 |features|..X.Sect|
|00000920| 69 6f 6e 20 37 20 64 65 | 73 63 72 69 62 65 73 20 |ion 7 de|scribes |
|00000930| 6d 79 20 6e 65 77 2c 20 | 73 65 63 75 72 65 2c 20 |my new, |secure, |
|00000940| 65 78 74 72 65 6d 65 6c | 79 20 73 69 6d 70 6c 65 |extremel|y simple|
|00000950| 20 6a 6f 62 20 63 6f 6e | 74 72 6f 6c 0a 70 72 6f | job con|trol.pro|
|00000960| 67 72 61 6d 6d 69 6e 67 | 20 69 6e 74 65 72 66 61 |gramming| interfa|
|00000970| 63 65 20 5b 31 5d 2e 20 | 28 54 68 65 20 69 6e 74 |ce [1]. |(The int|
|00000980| 65 72 66 61 63 65 20 77 | 61 73 20 69 6e 73 70 69 |erface w|as inspi|
|00000990| 72 65 64 20 62 79 20 61 | 20 63 6f 6d 6d 65 6e 74 |red by a| comment|
|000009a0| 20 66 72 6f 6d 0a 43 68 | 72 69 73 20 54 6f 72 65 | from.Ch|ris Tore|
|000009b0| 6b 2e 20 49 74 20 77 61 | 73 20 6d 6f 64 69 66 69 |k. It wa|s modifi|
|000009c0| 65 64 20 73 6c 69 67 68 | 74 6c 79 20 69 6e 20 72 |ed sligh|tly in r|
|000009d0| 65 73 70 6f 6e 73 65 20 | 74 6f 20 63 72 69 74 69 |esponse |to criti|
|000009e0| 63 69 73 6d 20 62 79 0a | 4a 6f 68 6e 20 43 61 72 |cism by.|John Car|
|000009f0| 72 2e 20 49 74 20 69 73 | 20 64 65 64 69 63 61 74 |r. It is| dedicat|
|00000a00| 65 64 20 74 6f 20 4d 61 | 72 63 20 54 65 69 74 65 |ed to Ma|rc Teite|
|00000a10| 6c 62 61 75 6d 2e 29 20 | 54 68 65 20 69 6e 74 65 |lbaum.) |The inte|
|00000a20| 72 66 61 63 65 20 69 73 | 20 65 6e 6f 75 67 68 0a |rface is| enough.|
|00000a30| 74 6f 20 6c 65 74 20 70 | 72 6f 67 72 61 6d 6d 65 |to let p|rogramme|
|00000a40| 72 73 20 69 6d 70 6c 65 | 6d 65 6e 74 20 61 20 6a |rs imple|ment a j|
|00000a50| 6f 62 20 63 6f 6e 74 72 | 6f 6c 20 73 68 65 6c 6c |ob contr|ol shell|
|00000a60| 20 6f 72 20 61 6e 79 20 | 6f 74 68 65 72 20 6a 6f | or any |other jo|
|00000a70| 62 0a 63 6f 6e 74 72 6f | 6c 2d 63 6f 67 6e 69 7a |b.contro|l-cogniz|
|00000a80| 61 6e 74 20 61 70 70 6c | 69 63 61 74 69 6f 6e 73 |ant appl|ications|
|00000a90| 2e 20 49 74 20 73 6f 6c | 76 65 73 20 61 6c 6c 20 |. It sol|ves all |
|00000aa0| 74 68 65 20 70 72 6f 62 | 6c 65 6d 73 20 74 68 61 |the prob|lems tha|
|00000ab0| 74 20 50 4f 53 49 58 0a | 73 65 73 73 69 6f 6e 73 |t POSIX.|sessions|
|00000ac0| 20 77 65 72 65 20 6d 65 | 61 6e 74 20 74 6f 20 73 | were me|ant to s|
|00000ad0| 6f 6c 76 65 2c 20 62 75 | 74 20 69 74 20 69 73 20 |olve, bu|t it is |
|00000ae0| 6d 75 63 68 2c 20 6d 75 | 63 68 20 73 69 6d 70 6c |much, mu|ch simpl|
|00000af0| 65 72 2c 20 61 6e 64 20 | 63 61 6e 20 62 65 0a 61 |er, and |can be.a|
|00000b00| 64 64 65 64 20 74 6f 20 | 61 20 73 79 73 74 65 6d |dded to |a system|
|00000b10| 20 77 69 74 68 20 61 20 | 6d 69 6e 69 6d 75 6d 20 | with a |minimum |
|00000b20| 6f 66 20 65 66 66 6f 72 | 74 2e 20 49 74 20 63 61 |of effor|t. It ca|
|00000b30| 6e 20 65 76 65 6e 20 62 | 65 20 61 64 64 65 64 20 |n even b|e added |
|00000b40| 74 6f 20 61 0a 42 53 44 | 20 73 79 73 74 65 6d 2c |to a.BSD| system,|
|00000b50| 20 61 73 20 64 69 73 63 | 75 73 73 65 64 20 69 6e | as disc|ussed in|
|00000b60| 20 73 65 63 74 69 6f 6e | 20 38 2d 2d 2d 69 74 20 | section| 8---it |
|00000b70| 64 6f 65 73 20 6e 6f 74 | 20 69 6e 74 65 72 66 65 |does not| interfe|
|00000b80| 72 65 20 77 69 74 68 20 | 74 68 65 0a 6f 6c 64 20 |re with |the.old |
|00000b90| 6a 6f 62 20 63 6f 6e 74 | 72 6f 6c 20 6d 6f 64 65 |job cont|rol mode|
|00000ba0| 6c 20 69 6e 20 61 6e 79 | 20 77 61 79 2e 20 54 68 |l in any| way. Th|
|00000bb0| 69 73 20 77 69 6c 6c 20 | 67 69 76 65 20 70 72 6f |is will |give pro|
|00000bc0| 67 72 61 6d 6d 65 72 73 | 20 61 20 63 68 6f 69 63 |grammers| a choic|
|00000bd0| 65 0a 62 65 74 77 65 65 | 6e 20 74 68 65 20 6f 6c |e.betwee|n the ol|
|00000be0| 64 65 72 2c 20 6d 6f 72 | 65 20 63 6f 6d 70 6c 69 |der, mor|e compli|
|00000bf0| 63 61 74 65 64 20 69 6e | 74 65 72 66 61 63 65 20 |cated in|terface |
|00000c00| 61 6e 64 20 74 68 69 73 | 20 6e 65 77 2c 20 65 61 |and this| new, ea|
|00000c10| 73 79 2d 74 6f 2d 75 73 | 65 0a 69 6e 74 65 72 66 |sy-to-us|e.interf|
|00000c20| 61 63 65 2e 0a 58 0a 53 | 65 63 74 69 6f 6e 20 39 |ace..X.S|ection 9|
|00000c30| 20 6c 69 73 74 73 20 73 | 65 76 65 72 61 6c 20 6a | lists s|everal j|
|00000c40| 6f 62 20 63 6f 6e 74 72 | 6f 6c 20 70 72 6f 67 72 |ob contr|ol progr|
|00000c50| 61 6d 6d 69 6e 67 20 74 | 65 63 68 6e 69 71 75 65 |amming t|echnique|
|00000c60| 73 2e 20 46 69 6e 61 6c | 6c 79 2c 0a 73 65 63 74 |s. Final|ly,.sect|
|00000c70| 69 6f 6e 20 31 30 2c 20 | 61 67 61 69 6e 20 66 72 |ion 10, |again fr|
|00000c80| 6f 6d 20 74 68 65 20 70 | 6f 69 6e 74 20 6f 66 20 |om the p|oint of |
|00000c90| 76 69 65 77 20 6f 66 20 | 61 20 73 79 73 74 65 6d |view of |a system|
|00000ca0| 20 77 69 74 68 6f 75 74 | 20 6a 6f 62 0a 63 6f 6e | without| job.con|
|00000cb0| 74 72 6f 6c 2c 20 6c 69 | 73 74 73 20 73 6f 6d 65 |trol, li|sts some|
|00000cc0| 20 63 6f 6d 6d 6f 6e 20 | 6d 61 63 72 6f 73 20 61 | common |macros a|
|00000cd0| 6e 64 20 73 69 6d 69 6c | 61 72 20 63 70 70 2d 6c |nd simil|ar cpp-l|
|00000ce0| 65 76 65 6c 20 65 78 74 | 65 6e 73 69 6f 6e 73 0a |evel ext|ensions.|
|00000cf0| 77 68 69 63 68 20 6d 61 | 6b 65 20 6a 6f 62 20 63 |which ma|ke job c|
|00000d00| 6f 6e 74 72 6f 6c 20 70 | 72 6f 67 72 61 6d 73 20 |ontrol p|rograms |
|00000d10| 65 61 73 69 65 72 20 74 | 6f 20 70 6f 72 74 2e 0a |easier t|o port..|
|00000d20| 58 0a 58 0a 58 32 2e 20 | 4e 65 77 20 6b 65 72 6e |X.X.X2. |New kern|
|00000d30| 65 6c 20 73 74 72 75 63 | 74 75 72 65 73 0a 58 0a |el struc|tures.X.|
|00000d40| 58 45 61 63 68 20 70 72 | 6f 63 65 73 73 20 60 60 |XEach pr|ocess ``|
|00000d50| 69 73 20 61 20 6d 65 6d | 62 65 72 20 6f 66 27 27 |is a mem|ber of''|
|00000d60| 20 61 20 70 72 6f 63 65 | 73 73 20 67 72 6f 75 70 | a proce|ss group|
|00000d70| 2e 20 49 6e 20 6f 74 68 | 65 72 20 77 6f 72 64 73 |. In oth|er words|
|00000d80| 2c 20 74 68 65 72 65 27 | 73 0a 61 20 70 5f 70 67 |, there'|s.a p_pg|
|00000d90| 72 70 20 69 6e 74 65 67 | 65 72 20 69 6e 73 69 64 |rp integ|er insid|
|00000da0| 65 20 73 74 72 75 63 74 | 20 70 72 6f 63 2e 20 69 |e struct| proc. i|
|00000db0| 6e 69 74 20 73 74 61 72 | 74 73 20 6f 75 74 20 69 |nit star|ts out i|
|00000dc0| 6e 20 70 72 6f 63 65 73 | 73 20 67 72 6f 75 70 20 |n proces|s group |
|00000dd0| 30 2e 0a 50 72 6f 63 65 | 73 73 20 67 72 6f 75 70 |0..Proce|ss group|
|00000de0| 73 20 72 65 6d 61 69 6e | 20 74 68 65 20 73 61 6d |s remain| the sam|
|00000df0| 65 20 61 63 72 6f 73 73 | 20 66 6f 72 6b 28 29 20 |e across| fork() |
|00000e00| 61 6e 64 20 65 78 65 63 | 28 29 2e 0a 58 0a 58 45 |and exec|()..X.XE|
|00000e10| 61 63 68 20 74 74 79 20 | 68 61 73 20 61 20 60 60 |ach tty |has a ``|
|00000e20| 66 6f 72 65 67 72 6f 75 | 6e 64 27 27 20 70 72 6f |foregrou|nd'' pro|
|00000e30| 63 65 73 73 20 67 72 6f | 75 70 2e 20 49 6e 20 6f |cess gro|up. In o|
|00000e40| 74 68 65 72 20 77 6f 72 | 64 73 2c 20 74 68 65 72 |ther wor|ds, ther|
|00000e50| 65 27 73 20 61 0a 74 5f | 70 67 72 70 20 69 6e 74 |e's a.t_|pgrp int|
|00000e60| 65 67 65 72 20 69 6e 73 | 69 64 65 20 73 74 72 75 |eger ins|ide stru|
|00000e70| 63 74 20 74 74 79 2e 20 | 28 53 79 73 74 65 6d 73 |ct tty. |(Systems|
|00000e80| 20 77 68 65 72 65 20 74 | 74 79 73 20 61 72 65 20 | where t|tys are |
|00000e90| 69 6d 70 6c 65 6d 65 6e | 74 65 64 0a 64 69 66 66 |implemen|ted.diff|
|00000ea0| 65 72 65 6e 74 6c 79 2c | 20 65 2e 67 2e 2c 20 76 |erently,| e.g., v|
|00000eb0| 69 61 20 73 74 72 65 61 | 6d 73 2c 20 77 69 6c 6c |ia strea|ms, will|
|00000ec0| 20 68 61 76 65 20 74 6f | 20 73 74 6f 72 65 20 74 | have to| store t|
|00000ed0| 68 69 73 20 69 6e 66 6f | 72 6d 61 74 69 6f 6e 0a |his info|rmation.|
|00000ee0| 73 6f 6d 65 77 68 65 72 | 65 20 65 6c 73 65 2e 29 |somewher|e else.)|
|00000ef0| 20 41 20 74 74 79 20 6f | 70 65 6e 65 64 20 66 6f | A tty o|pened fo|
|00000f00| 72 20 74 68 65 20 66 69 | 72 73 74 20 74 69 6d 65 |r the fi|rst time|
|00000f10| 20 68 61 73 20 74 5f 70 | 67 72 70 20 73 65 74 20 | has t_p|grp set |
|00000f20| 74 6f 20 30 2e 0a 58 45 | 61 63 68 20 74 74 79 20 |to 0..XE|ach tty |
|00000f30| 61 6c 73 6f 20 68 61 73 | 20 6f 6e 65 20 65 78 74 |also has| one ext|
|00000f40| 72 61 20 6b 65 79 62 6f | 61 72 64 20 63 68 61 72 |ra keybo|ard char|
|00000f50| 61 63 74 65 72 2c 20 74 | 68 65 20 73 75 73 70 65 |acter, t|he suspe|
|00000f60| 6e 64 20 63 68 61 72 61 | 63 74 65 72 2c 0a 77 69 |nd chara|cter,.wi|
|00000f70| 74 68 20 61 20 64 65 66 | 61 75 6c 74 20 6f 66 20 |th a def|ault of |
|00000f80| 32 36 20 28 5e 5a 29 2e | 0a 58 0a 54 68 65 72 65 |26 (^Z).|.X.There|
|00000f90| 20 69 73 20 61 20 6e 65 | 77 20 70 72 6f 63 65 73 | is a ne|w proces|
|00000fa0| 73 20 73 74 61 74 65 20 | 28 69 2e 65 2e 2c 20 70 |s state |(i.e., p|
|00000fb0| 5f 73 74 61 74 20 76 61 | 6c 75 65 29 3a 20 53 53 |_stat va|lue): SS|
|00000fc0| 54 4f 50 2e 20 28 70 73 | 20 75 73 75 61 6c 6c 79 |TOP. (ps| usually|
|00000fd0| 0a 72 65 70 6f 72 74 73 | 20 74 68 69 73 20 73 74 |.reports| this st|
|00000fe0| 61 74 65 20 61 73 20 54 | 2e 29 20 57 68 65 6e 20 |ate as T|.) When |
|00000ff0| 61 20 70 72 6f 63 65 73 | 73 20 69 73 20 69 6e 20 |a proces|s is in |
|00001000| 74 68 69 73 20 73 74 61 | 74 65 2c 20 69 74 20 67 |this sta|te, it g|
|00001010| 65 74 73 20 6e 6f 0a 43 | 50 55 20 74 69 6d 65 2e |ets no.C|PU time.|
|00001020| 20 41 6c 6c 20 73 69 67 | 6e 61 6c 73 20 61 72 65 | All sig|nals are|
|00001030| 20 62 6c 6f 63 6b 65 64 | 20 75 6e 74 69 6c 20 69 | blocked| until i|
|00001040| 74 20 6c 65 61 76 65 73 | 20 74 68 65 20 73 74 61 |t leaves| the sta|
|00001050| 74 65 2e 20 4e 6f 74 65 | 20 74 68 61 74 0a 73 79 |te. Note| that.sy|
|00001060| 73 74 65 6d 73 20 77 69 | 74 68 20 73 6f 6d 65 20 |stems wi|th some |
|00001070| 66 6f 72 6d 20 6f 66 20 | 70 72 6f 63 65 73 73 20 |form of |process |
|00001080| 74 72 61 63 69 6e 67 20 | 28 65 2e 67 2e 2c 20 70 |tracing |(e.g., p|
|00001090| 74 72 61 63 65 28 32 29 | 29 20 61 6c 72 65 61 64 |trace(2)|) alread|
|000010a0| 79 20 68 61 76 65 0a 53 | 53 54 4f 50 2e 0a 58 0a |y have.S|STOP..X.|
|000010b0| 58 0a 58 33 2e 20 53 69 | 67 6e 61 6c 73 0a 58 0a |X.X3. Si|gnals.X.|
|000010c0| 54 68 65 72 65 20 61 72 | 65 20 66 69 76 65 20 6e |There ar|e five n|
|000010d0| 65 77 20 73 69 67 6e 61 | 6c 73 20 64 65 63 6c 61 |ew signa|ls decla|
|000010e0| 72 65 64 20 69 6e 20 3c | 73 69 67 6e 61 6c 2e 68 |red in <|signal.h|
|000010f0| 3e 3a 20 53 49 47 53 54 | 4f 50 20 28 31 37 29 2c |>: SIGST|OP (17),|
|00001100| 20 53 49 47 54 53 54 50 | 0a 58 28 31 38 29 2c 20 | SIGTSTP|.X(18), |
|00001110| 53 49 47 43 4f 4e 54 20 | 28 31 39 29 2c 20 53 49 |SIGCONT |(19), SI|
|00001120| 47 54 54 49 4e 20 28 32 | 31 29 2c 20 53 49 47 54 |GTTIN (2|1), SIGT|
|00001130| 54 4f 55 20 28 32 32 29 | 2e 20 28 54 68 65 20 6e |TOU (22)|. (The n|
|00001140| 75 6d 62 65 72 73 20 69 | 6e 0a 70 61 72 65 6e 74 |umbers i|n.parent|
|00001150| 68 65 73 65 73 20 61 72 | 65 20 74 68 65 20 73 74 |heses ar|e the st|
|00001160| 61 6e 64 61 72 64 20 42 | 53 44 20 76 61 6c 75 65 |andard B|SD value|
|00001170| 73 2e 29 20 41 6e 79 20 | 63 6f 64 65 20 77 68 69 |s.) Any |code whi|
|00001180| 63 68 20 77 6f 72 6b 73 | 20 77 69 74 68 20 62 69 |ch works| with bi|
|00001190| 74 0a 6d 61 73 6b 73 20 | 72 65 70 72 65 73 65 6e |t.masks |represen|
|000011a0| 74 69 6e 67 20 73 69 67 | 6e 61 6c 73 20 6d 75 73 |ting sig|nals mus|
|000011b0| 74 20 62 65 20 70 72 65 | 70 61 72 65 64 20 74 6f |t be pre|pared to|
|000011c0| 20 77 6f 72 6b 20 77 69 | 74 68 20 33 32 2d 62 69 | work wi|th 32-bi|
|000011d0| 74 20 6d 61 73 6b 73 2e | 0a 58 0a 54 68 65 20 64 |t masks.|.X.The d|
|000011e0| 65 66 61 75 6c 74 20 61 | 63 74 69 6f 6e 20 6f 66 |efault a|ction of|
|000011f0| 20 61 20 70 72 6f 63 65 | 73 73 20 72 65 63 65 69 | a proce|ss recei|
|00001200| 76 69 6e 67 20 53 49 47 | 53 54 4f 50 2c 20 53 49 |ving SIG|STOP, SI|
|00001210| 47 54 53 54 50 2c 20 53 | 49 47 54 54 49 4e 2c 20 |GTSTP, S|IGTTIN, |
|00001220| 6f 72 0a 53 49 47 54 54 | 4f 55 20 69 73 20 74 6f |or.SIGTT|OU is to|
|00001230| 20 73 74 6f 70 2c 20 69 | 2e 65 2e 2c 20 65 6e 74 | stop, i|.e., ent|
|00001240| 65 72 20 74 68 65 20 53 | 53 54 4f 50 20 73 74 61 |er the S|STOP sta|
|00001250| 74 65 20 61 6e 64 2c 20 | 61 73 20 64 65 74 61 69 |te and, |as detai|
|00001260| 6c 65 64 20 62 65 6c 6f | 77 2c 0a 74 6f 20 67 65 |led belo|w,.to ge|
|00001270| 6e 65 72 61 74 65 20 61 | 20 53 49 47 43 48 4c 44 |nerate a| SIGCHLD|
|00001280| 2e 20 53 49 47 53 54 4f | 50 20 63 61 6e 6e 6f 74 |. SIGSTO|P cannot|
|00001290| 20 62 65 20 62 6c 6f 63 | 6b 65 64 2c 20 63 61 75 | be bloc|ked, cau|
|000012a0| 67 68 74 2c 20 6f 72 20 | 69 67 6e 6f 72 65 64 2e |ght, or |ignored.|
|000012b0| 0a 58 28 60 60 42 6c 6f | 63 6b 69 6e 67 27 27 20 |.X(``Blo|cking'' |
|000012c0| 72 65 66 65 72 73 20 74 | 6f 20 61 6e 79 20 6d 65 |refers t|o any me|
|000012d0| 63 68 61 6e 69 73 6d 20 | 62 79 20 77 68 69 63 68 |chanism |by which|
|000012e0| 20 74 68 65 20 72 65 63 | 65 69 70 74 20 6f 66 20 | the rec|eipt of |
|000012f0| 61 20 73 69 67 6e 61 6c | 0a 69 73 20 64 65 66 65 |a signal|.is defe|
|00001300| 72 72 65 64 2e 20 42 53 | 44 20 70 72 6f 76 69 64 |rred. BS|D provid|
|00001310| 65 73 20 73 69 67 62 6c | 6f 63 6b 28 29 20 61 6e |es sigbl|ock() an|
|00001320| 64 20 73 69 67 73 65 74 | 6d 61 73 6b 28 29 20 74 |d sigset|mask() t|
|00001330| 6f 20 6d 61 6e 69 70 75 | 6c 61 74 65 20 61 0a 62 |o manipu|late a.b|
|00001340| 69 74 20 6d 61 73 6b 20 | 6f 66 20 62 6c 6f 63 6b |it mask |of block|
|00001350| 65 64 20 73 69 67 6e 61 | 6c 73 2e 20 4f 6e 20 73 |ed signa|ls. On s|
|00001360| 79 73 74 65 6d 73 20 77 | 69 74 68 6f 75 74 20 61 |ystems w|ithout a|
|00001370| 20 73 69 6d 69 6c 61 72 | 20 6d 65 63 68 61 6e 69 | similar| mechani|
|00001380| 73 6d 2c 0a 53 49 47 53 | 54 4f 50 20 6f 62 76 69 |sm,.SIGS|TOP obvi|
|00001390| 6f 75 73 6c 79 20 63 61 | 6e 27 74 20 62 65 20 62 |ously ca|n't be b|
|000013a0| 6c 6f 63 6b 65 64 20 69 | 6e 20 74 68 65 20 66 69 |locked i|n the fi|
|000013b0| 72 73 74 20 70 6c 61 63 | 65 2e 20 57 68 61 74 27 |rst plac|e. What'|
|000013c0| 73 20 69 6d 70 6f 72 74 | 61 6e 74 0a 69 73 20 74 |s import|ant.is t|
|000013d0| 68 74 20 53 49 47 53 54 | 4f 50 20 61 6c 77 61 79 |ht SIGST|OP alway|
|000013e0| 73 20 74 61 6b 65 20 65 | 66 66 65 63 74 20 69 6d |s take e|ffect im|
|000013f0| 6d 65 64 69 61 74 65 6c | 79 2e 29 0a 58 0a 41 6e |mediatel|y.).X.An|
|00001400| 79 20 70 72 6f 63 65 73 | 73 20 77 68 69 63 68 20 |y proces|s which |
|00001410| 72 65 63 65 69 76 65 73 | 20 53 49 47 43 4f 4e 54 |receives| SIGCONT|
|00001420| 20 77 69 6c 6c 20 63 6f | 6e 74 69 6e 75 65 2c 20 | will co|ntinue, |
|00001430| 69 2e 65 2e 2c 20 6c 65 | 61 76 65 20 74 68 65 20 |i.e., le|ave the |
|00001440| 53 53 54 4f 50 0a 73 74 | 61 74 65 3b 20 74 68 69 |SSTOP.st|ate; thi|
|00001450| 73 20 69 73 20 69 6e 20 | 61 64 64 69 74 69 6f 6e |s is in |addition|
|00001460| 20 74 6f 20 61 6e 79 20 | 73 69 67 6e 61 6c 20 68 | to any |signal h|
|00001470| 61 6e 64 6c 65 72 20 69 | 6e 73 74 61 6c 6c 65 64 |andler i|nstalled|
|00001480| 2e 20 28 4f 62 76 69 6f | 75 73 6c 79 0a 74 68 65 |. (Obvio|usly.the|
|00001490| 20 70 72 6f 63 65 73 73 | 20 63 61 6e 6e 6f 74 20 | process| cannot |
|000014a0| 65 78 65 63 75 74 65 20 | 61 20 73 69 67 6e 61 6c |execute |a signal|
|000014b0| 20 68 61 6e 64 6c 65 72 | 20 69 66 20 69 74 27 73 | handler| if it's|
|000014c0| 20 69 6e 20 74 68 65 20 | 53 53 54 4f 50 20 73 74 | in the |SSTOP st|
|000014d0| 61 74 65 2c 0a 72 65 63 | 65 69 76 69 6e 67 20 6e |ate,.rec|eiving n|
|000014e0| 6f 20 43 50 55 20 74 69 | 6d 65 21 29 20 53 49 47 |o CPU ti|me!) SIG|
|000014f0| 43 4f 4e 54 20 63 61 6e | 6e 6f 74 20 62 65 20 62 |CONT can|not be b|
|00001500| 6c 6f 63 6b 65 64 2e 20 | 41 20 70 72 6f 63 65 73 |locked. |A proces|
|00001510| 73 20 69 73 20 61 6c 77 | 61 79 73 0a 61 62 6c 65 |s is alw|ays.able|
|00001520| 20 74 6f 20 73 65 6e 64 | 20 53 49 47 43 4f 4e 54 | to send| SIGCONT|
|00001530| 20 74 6f 20 61 6e 79 20 | 6f 66 20 69 74 73 20 63 | to any |of its c|
|00001540| 68 69 6c 64 72 65 6e 2c | 20 72 65 67 61 72 64 6c |hildren,| regardl|
|00001550| 65 73 73 20 6f 66 20 70 | 65 72 6d 69 73 73 69 6f |ess of p|ermissio|
|00001560| 6e 0a 63 68 65 63 6b 73 | 2e 20 28 42 53 44 20 61 |n.checks|. (BSD a|
|00001570| 63 74 75 61 6c 6c 79 20 | 6c 65 74 73 20 79 6f 75 |ctually |lets you|
|00001580| 20 73 65 6e 64 20 53 49 | 47 43 4f 4e 54 20 74 6f | send SI|GCONT to|
|00001590| 20 61 6e 79 20 64 65 73 | 63 65 6e 64 61 6e 74 2e | any des|cendant.|
|000015a0| 20 53 6f 6d 65 0a 70 6f | 70 75 6c 61 72 20 42 53 | Some.po|pular BS|
|000015b0| 44 20 76 61 72 69 61 6e | 74 73 20 64 6f 20 6e 6f |D varian|ts do no|
|000015c0| 74 20 6f 62 65 79 20 74 | 68 69 73 20 72 75 6c 65 |t obey t|his rule|
|000015d0| 2e 29 0a 58 0a 57 68 65 | 6e 20 61 20 70 72 6f 63 |.).X.Whe|n a proc|
|000015e0| 65 73 73 20 65 6e 74 65 | 72 73 20 74 68 65 20 53 |ess ente|rs the S|
|000015f0| 53 54 4f 50 20 73 74 61 | 74 65 2c 20 69 74 20 67 |STOP sta|te, it g|
|00001600| 65 6e 65 72 61 74 65 73 | 20 61 20 53 49 47 43 48 |enerates| a SIGCH|
|00001610| 4c 44 20 28 61 6b 61 0a | 53 49 47 43 4c 44 29 20 |LD (aka.|SIGCLD) |
|00001620| 74 6f 20 69 74 73 20 70 | 61 72 65 6e 74 2e 20 54 |to its p|arent. T|
|00001630| 68 65 72 65 20 61 72 65 | 20 73 65 76 65 72 61 6c |here are| several|
|00001640| 20 63 6f 6e 66 6c 69 63 | 74 69 6e 67 20 73 65 74 | conflic|ting set|
|00001650| 73 20 6f 66 20 73 65 6d | 61 6e 74 69 63 73 0a 66 |s of sem|antics.f|
|00001660| 6f 72 20 53 49 47 43 48 | 4c 44 2f 53 49 47 43 4c |or SIGCH|LD/SIGCL|
|00001670| 44 20 28 65 2e 67 2e 2c | 20 77 68 61 74 20 68 61 |D (e.g.,| what ha|
|00001680| 70 70 65 6e 73 20 77 68 | 65 6e 20 69 74 27 73 20 |ppens wh|en it's |
|00001690| 69 67 6e 6f 72 65 64 3f | 20 77 68 65 6e 20 61 72 |ignored?| when ar|
|000016a0| 65 0a 7a 6f 6d 62 69 65 | 73 20 63 72 65 61 74 65 |e.zombie|s create|
|000016b0| 64 3f 29 20 6f 6e 20 76 | 61 72 69 6f 75 73 20 73 |d?) on v|arious s|
|000016c0| 79 73 74 65 6d 73 2c 20 | 6e 6f 6e 65 20 6f 66 20 |ystems, |none of |
|000016d0| 77 68 69 63 68 20 68 61 | 76 65 20 61 6e 79 20 72 |which ha|ve any r|
|000016e0| 65 6c 65 76 61 6e 63 65 | 0a 74 6f 20 6a 6f 62 20 |elevance|.to job |
|000016f0| 63 6f 6e 74 72 6f 6c 2e | 0a 58 0a 58 0a 58 34 2e |control.|.X.X.X4.|
|00001700| 20 57 61 69 74 69 6e 67 | 0a 58 0a 57 68 65 6e 20 | Waiting|.X.When |
|00001710| 74 68 65 20 70 61 72 65 | 6e 74 2c 20 65 69 74 68 |the pare|nt, eith|
|00001720| 65 72 20 75 70 6f 6e 20 | 72 65 63 65 69 76 69 6e |er upon |receivin|
|00001730| 67 20 61 20 53 49 47 43 | 48 4c 44 20 6f 72 20 61 |g a SIGC|HLD or a|
|00001740| 74 20 61 6e 79 20 6f 74 | 68 65 72 20 74 69 6d 65 |t any ot|her time|
|00001750| 2c 0a 64 6f 65 73 20 61 | 20 77 61 69 74 28 29 2c |,.does a| wait(),|
|00001760| 20 69 74 20 77 69 6c 6c | 20 6e 6f 74 20 73 65 65 | it will| not see|
|00001770| 20 61 6e 79 20 73 74 6f | 70 70 65 64 20 63 68 69 | any sto|pped chi|
|00001780| 6c 64 72 65 6e 2d 2d 2d | 69 2e 65 2e 2c 20 6a 6f |ldren---|i.e., jo|
|00001790| 62 20 63 6f 6e 74 72 6f | 6c 0a 64 6f 65 73 6e 27 |b contro|l.doesn'|
|000017a0| 74 20 63 68 61 6e 67 65 | 20 74 68 65 20 73 65 6d |t change| the sem|
|000017b0| 61 6e 74 69 63 73 20 6f | 66 20 77 61 69 74 28 29 |antics o|f wait()|
|000017c0| 2e 20 28 50 72 6f 63 65 | 73 73 20 74 72 61 63 69 |. (Proce|ss traci|
|000017d0| 6e 67 20 64 6f 65 73 2c | 20 62 75 74 20 74 68 61 |ng does,| but tha|
|000017e0| 74 0a 69 73 20 61 6c 73 | 6f 20 69 72 72 65 6c 65 |t.is als|o irrele|
|000017f0| 76 61 6e 74 20 74 6f 20 | 6a 6f 62 20 63 6f 6e 74 |vant to |job cont|
|00001800| 72 6f 6c 2e 29 20 54 68 | 65 72 65 20 69 73 20 61 |rol.) Th|ere is a|
|00001810| 20 6e 65 77 20 73 79 73 | 74 65 6d 20 63 61 6c 6c | new sys|tem call|
|00001820| 2c 20 77 61 69 74 32 2c | 0a 77 68 69 63 68 20 6c |, wait2,|.which l|
|00001830| 65 74 73 20 74 68 65 20 | 70 61 72 65 6e 74 20 73 |ets the |parent s|
|00001840| 65 65 20 73 74 6f 70 70 | 65 64 20 63 68 69 6c 64 |ee stopp|ed child|
|00001850| 72 65 6e 3a 0a 58 0a 58 | 20 20 23 69 6e 63 6c 75 |ren:.X.X| #inclu|
|00001860| 64 65 20 3c 73 79 73 2f | 77 61 69 74 2e 68 3e 0a |de <sys/|wait.h>.|
|00001870| 58 0a 58 20 20 69 6e 74 | 20 77 61 69 74 32 28 73 |X.X int| wait2(s|
|00001880| 74 61 74 75 73 2c 6f 70 | 74 69 6f 6e 73 29 0a 58 |tatus,op|tions).X|
|00001890| 20 20 69 6e 74 20 2a 73 | 74 61 74 75 73 3b 0a 58 | int *s|tatus;.X|
|000018a0| 20 20 69 6e 74 20 6f 70 | 74 69 6f 6e 73 3b 0a 58 | int op|tions;.X|
|000018b0| 0a 58 28 49 6e 20 66 61 | 63 74 2c 20 42 53 44 20 |.X(In fa|ct, BSD |
|000018c0| 68 61 73 20 61 20 77 61 | 69 74 33 28 29 20 63 61 |has a wa|it3() ca|
|000018d0| 6c 6c 20 69 6e 73 74 65 | 61 64 20 6f 66 20 77 61 |ll inste|ad of wa|
|000018e0| 69 74 32 28 29 3b 20 74 | 68 65 20 61 62 6f 76 65 |it2(); t|he above|
|000018f0| 20 63 61 6c 6c 20 69 73 | 0a 74 68 65 20 73 61 6d | call is|.the sam|
|00001900| 65 20 61 73 20 77 61 69 | 74 33 28 73 74 61 74 75 |e as wai|t3(statu|
|00001910| 73 2c 6f 70 74 69 6f 6e | 73 2c 28 73 74 72 75 63 |s,option|s,(struc|
|00001920| 74 20 72 75 73 61 67 65 | 20 2a 29 20 30 29 2e 20 |t rusage| *) 0). |
|00001930| 53 65 65 20 73 65 63 74 | 69 6f 6e 20 31 30 0a 66 |See sect|ion 10.f|
|00001940| 6f 72 20 66 75 72 74 68 | 65 72 20 64 65 74 61 69 |or furth|er detai|
|00001950| 6c 73 2e 29 20 6f 70 74 | 69 6f 6e 73 20 69 73 20 |ls.) opt|ions is |
|00001960| 61 20 62 69 74 20 66 69 | 65 6c 64 2e 20 59 6f 75 |a bit fi|eld. You|
|00001970| 20 68 61 76 65 20 74 6f | 20 64 65 66 69 6e 65 20 | have to| define |
|00001980| 74 77 6f 0a 62 69 74 73 | 2c 20 57 4e 4f 48 41 4e |two.bits|, WNOHAN|
|00001990| 47 20 61 6e 64 20 57 55 | 4e 54 52 41 43 45 44 2c |G and WU|NTRACED,|
|000019a0| 20 69 6e 20 3c 73 79 73 | 2f 77 61 69 74 2e 68 3e | in <sys|/wait.h>|
|000019b0| 2c 20 66 6f 72 20 75 73 | 65 20 61 73 20 6f 70 74 |, for us|e as opt|
|000019c0| 69 6f 6e 73 2e 0a 58 0a | 4e 6f 72 6d 61 6c 6c 79 |ions..X.|Normally|
|000019d0| 20 77 61 69 74 32 28 29 | 20 61 63 74 73 20 6c 69 | wait2()| acts li|
|000019e0| 6b 65 20 77 61 69 74 28 | 29 3a 20 69 74 20 62 6c |ke wait(|): it bl|
|000019f0| 6f 63 6b 73 20 77 61 69 | 74 69 6e 67 20 66 6f 72 |ocks wai|ting for|
|00001a00| 20 61 20 63 68 69 6c 64 | 20 74 6f 20 64 69 65 0a | a child| to die.|
|00001a10| 61 6e 64 20 74 68 65 6e | 20 72 65 74 75 72 6e 73 |and then| returns|
|00001a20| 20 74 68 65 20 64 65 61 | 64 20 70 69 64 2c 20 6f | the dea|d pid, o|
|00001a30| 72 20 72 65 74 75 72 6e | 73 20 2d 31 20 69 6d 6d |r return|s -1 imm|
|00001a40| 65 64 69 61 74 65 6c 79 | 20 69 66 20 74 68 65 72 |ediately| if ther|
|00001a50| 65 20 61 72 65 20 6e 6f | 0a 6c 69 76 65 20 63 68 |e are no|.live ch|
|00001a60| 69 6c 64 72 65 6e 2e 20 | 49 66 20 6f 70 74 69 6f |ildren. |If optio|
|00001a70| 6e 73 20 69 6e 63 6c 75 | 64 65 73 20 57 4e 4f 48 |ns inclu|des WNOH|
|00001a80| 41 4e 47 2c 20 77 61 69 | 74 32 28 29 20 77 69 6c |ANG, wai|t2() wil|
|00001a90| 6c 20 72 65 74 75 72 6e | 20 30 0a 69 6d 6d 65 64 |l return| 0.immed|
|00001aa0| 69 61 74 65 6c 79 20 69 | 6e 73 74 65 61 64 20 6f |iately i|nstead o|
|00001ab0| 66 20 62 6c 6f 63 6b 69 | 6e 67 2e 20 49 66 20 6f |f blocki|ng. If o|
|00001ac0| 70 74 69 6f 6e 73 20 69 | 6e 63 6c 75 64 65 73 20 |ptions i|ncludes |
|00001ad0| 57 55 4e 54 52 41 43 45 | 44 2c 20 77 61 69 74 32 |WUNTRACE|D, wait2|
|00001ae0| 28 29 0a 77 69 6c 6c 20 | 72 65 74 75 72 6e 20 74 |().will |return t|
|00001af0| 68 65 20 70 69 64 20 6f | 66 20 61 20 73 74 6f 70 |he pid o|f a stop|
|00001b00| 70 65 64 20 63 68 69 6c | 64 20 61 73 20 77 65 6c |ped chil|d as wel|
|00001b10| 6c 20 61 73 20 74 68 65 | 20 70 69 64 20 6f 66 20 |l as the| pid of |
|00001b20| 61 20 64 65 61 64 0a 63 | 68 69 6c 64 2e 20 28 42 |a dead.c|hild. (B|
|00001b30| 79 20 66 61 72 20 74 68 | 65 20 6d 6f 73 74 20 63 |y far th|e most c|
|00001b40| 6f 6d 6d 6f 6e 20 6f 70 | 74 69 6f 6e 73 20 76 61 |ommon op|tions va|
|00001b50| 6c 75 65 20 69 73 20 57 | 4e 4f 48 41 4e 47 20 7c |lue is W|NOHANG ||
|00001b60| 20 57 55 4e 54 52 41 43 | 45 44 2e 29 0a 58 0a 41 | WUNTRAC|ED.).X.A|
|00001b70| 73 20 75 73 75 61 6c 2c | 20 77 68 65 6e 20 77 61 |s usual,| when wa|
|00001b80| 69 74 32 28 29 20 72 65 | 74 75 72 6e 73 20 61 20 |it2() re|turns a |
|00001b90| 70 69 64 2c 20 73 74 61 | 74 75 73 20 73 61 79 73 |pid, sta|tus says|
|00001ba0| 20 77 68 61 74 27 73 20 | 68 61 70 70 65 6e 65 64 | what's |happened|
|00001bb0| 20 74 6f 0a 74 68 61 74 | 20 70 69 64 2e 20 54 68 | to.that| pid. Th|
|00001bc0| 69 73 20 69 73 20 61 20 | 62 69 74 20 6d 6f 72 65 |is is a |bit more|
|00001bd0| 20 63 6f 6d 70 6c 69 63 | 61 74 65 64 20 74 68 61 | complic|ated tha|
|00001be0| 6e 20 62 65 66 6f 72 65 | 20 62 65 63 61 75 73 65 |n before| because|
|00001bf0| 20 73 74 61 74 75 73 20 | 61 6c 73 6f 0a 68 61 73 | status |also.has|
|00001c00| 20 74 6f 20 74 65 6c 6c | 20 74 68 65 20 70 61 72 | to tell| the par|
|00001c10| 65 6e 74 20 77 68 61 74 | 20 68 61 70 70 65 6e 65 |ent what| happene|
|00001c20| 64 20 69 66 20 74 68 65 | 20 63 68 69 6c 64 20 73 |d if the| child s|
|00001c30| 74 6f 70 70 65 64 2e 20 | 48 65 72 65 27 73 20 74 |topped. |Here's t|
|00001c40| 68 65 0a 77 68 6f 6c 65 | 20 73 74 6f 72 79 3a 20 |he.whole| story: |
|00001c50| 49 66 20 74 68 65 20 6c | 6f 77 20 37 20 62 69 74 |If the l|ow 7 bit|
|00001c60| 73 20 61 72 65 20 61 6c | 6c 20 73 65 74 2c 20 74 |s are al|l set, t|
|00001c70| 68 65 20 63 68 69 6c 64 | 20 68 61 73 20 69 6e 20 |he child| has in |
|00001c80| 66 61 63 74 0a 73 74 6f | 70 70 65 64 2e 20 49 66 |fact.sto|pped. If|
|00001c90| 20 6e 6f 6e 65 20 6f 66 | 20 74 68 6f 73 65 20 62 | none of| those b|
|00001ca0| 69 74 73 20 61 72 65 20 | 73 65 74 2c 20 74 68 65 |its are |set, the|
|00001cb0| 20 63 68 69 6c 64 20 68 | 61 73 20 65 78 69 74 65 | child h|as exite|
|00001cc0| 64 20 6e 6f 72 6d 61 6c | 6c 79 2e 0a 4f 74 68 65 |d normal|ly..Othe|
|00001cd0| 72 77 69 73 65 20 74 68 | 65 20 63 68 69 6c 64 20 |rwise th|e child |
|00001ce0| 68 61 73 20 62 65 65 6e | 20 74 65 72 6d 69 6e 61 |has been| termina|
|00001cf0| 74 65 64 20 62 79 20 61 | 20 73 69 67 6e 61 6c 2c |ted by a| signal,|
|00001d00| 20 61 6e 64 20 74 68 6f | 73 65 20 37 20 62 69 74 | and tho|se 7 bit|
|00001d10| 73 0a 73 61 79 20 77 68 | 69 63 68 20 73 69 67 6e |s.say wh|ich sign|
|00001d20| 61 6c 20 69 74 20 77 61 | 73 2e 20 28 49 66 20 74 |al it wa|s. (If t|
|00001d30| 68 65 20 38 74 68 20 62 | 69 74 20 69 73 20 73 65 |he 8th b|it is se|
|00001d40| 74 20 69 6e 20 74 68 61 | 74 20 63 61 73 65 2c 20 |t in tha|t case, |
|00001d50| 74 68 65 20 63 68 69 6c | 64 0a 64 75 6d 70 65 64 |the chil|d.dumped|
|00001d60| 20 63 6f 72 65 2e 29 20 | 49 66 20 74 68 65 20 63 | core.) |If the c|
|00001d70| 68 69 6c 64 20 68 61 73 | 20 73 74 6f 70 70 65 64 |hild has| stopped|
|00001d80| 2c 20 74 68 65 20 38 74 | 68 20 62 69 74 20 69 73 |, the 8t|h bit is|
|00001d90| 20 30 2c 20 61 6e 64 20 | 74 68 65 20 38 20 62 69 | 0, and |the 8 bi|
|00001da0| 74 73 0a 61 66 74 65 72 | 20 74 68 61 74 20 73 61 |ts.after| that sa|
|00001db0| 79 20 77 68 69 63 68 20 | 73 69 67 6e 61 6c 20 28 |y which |signal (|
|00001dc0| 53 49 47 54 54 4f 55 2c | 20 66 6f 72 20 69 6e 73 |SIGTTOU,| for ins|
|00001dd0| 74 61 6e 63 65 29 20 73 | 74 6f 70 70 65 64 20 74 |tance) s|topped t|
|00001de0| 68 65 20 70 72 6f 63 65 | 73 73 2e 0a 49 66 20 74 |he proce|ss..If t|
|00001df0| 68 65 20 63 68 69 6c 64 | 20 68 61 73 20 65 78 69 |he child| has exi|
|00001e00| 74 65 64 2c 20 74 68 65 | 20 38 74 68 20 62 69 74 |ted, the| 8th bit|
|00001e10| 20 69 73 20 30 2c 20 61 | 6e 64 20 74 68 65 20 38 | is 0, a|nd the 8|
|00001e20| 20 62 69 74 73 20 61 66 | 74 65 72 20 74 68 61 74 | bits af|ter that|
|00001e30| 0a 67 69 76 65 20 69 74 | 73 20 65 78 69 74 20 63 |.give it|s exit c|
|00001e40| 6f 64 65 20 6d 6f 64 20 | 32 35 36 2e 0a 58 0a 58 |ode mod |256..X.X|
|00001e50| 0a 58 35 2e 20 54 65 72 | 6d 69 6e 61 6c 2d 67 65 |.X5. Ter|minal-ge|
|00001e60| 6e 65 72 61 74 65 64 20 | 73 69 67 6e 61 6c 73 0a |nerated |signals.|
|00001e70| 58 0a 57 68 65 6e 20 74 | 68 65 20 69 6e 74 65 72 |X.When t|he inter|
|00001e80| 72 75 70 74 20 63 68 61 | 72 61 63 74 65 72 20 28 |rupt cha|racter (|
|00001e90| 74 79 70 69 63 61 6c 6c | 79 20 5e 43 20 75 6e 64 |typicall|y ^C und|
|00001ea0| 65 72 20 42 53 44 2c 20 | 44 45 4c 20 75 6e 64 65 |er BSD, |DEL unde|
|00001eb0| 72 20 53 79 73 74 65 6d | 20 56 29 0a 69 73 20 74 |r System| V).is t|
|00001ec0| 79 70 65 64 20 6f 6e 20 | 61 20 74 65 72 6d 69 6e |yped on |a termin|
|00001ed0| 61 6c 20 69 6e 20 63 6f | 6f 6b 65 64 20 6d 6f 64 |al in co|oked mod|
|00001ee0| 65 2c 20 69 66 20 74 68 | 65 20 74 65 72 6d 69 6e |e, if th|e termin|
|00001ef0| 61 6c 27 73 20 66 6f 72 | 65 67 72 6f 75 6e 64 0a |al's for|eground.|
|00001f00| 70 72 6f 63 65 73 73 20 | 67 72 6f 75 70 20 69 73 |process |group is|
|00001f10| 20 6e 6f 6e 2d 7a 65 72 | 6f 2c 20 65 76 65 72 79 | non-zer|o, every|
|00001f20| 20 70 72 6f 63 65 73 73 | 20 69 6e 20 74 68 61 74 | process| in that|
|00001f30| 20 70 72 6f 63 65 73 73 | 20 67 72 6f 75 70 20 69 | process| group i|
|00001f40| 73 20 73 65 6e 74 0a 53 | 49 47 49 4e 54 2e 20 53 |s sent.S|IGINT. S|
|00001f50| 69 6d 69 6c 61 72 6c 79 | 2c 20 74 68 65 20 71 75 |imilarly|, the qu|
|00001f60| 69 74 20 63 68 61 72 61 | 63 74 65 72 20 28 74 79 |it chara|cter (ty|
|00001f70| 70 69 63 61 6c 6c 79 20 | 5e 5c 20 75 6e 64 65 72 |pically |^\ under|
|00001f80| 20 42 53 44 29 20 67 65 | 6e 65 72 61 74 65 73 0a | BSD) ge|nerates.|
|00001f90| 53 49 47 51 55 49 54 2e | 20 49 66 20 61 20 74 65 |SIGQUIT.| If a te|
|00001fa0| 72 6d 69 6e 61 6c 20 69 | 73 20 60 60 68 75 6e 67 |rminal i|s ``hung|
|00001fb0| 20 75 70 27 27 2c 20 69 | 74 20 67 65 6e 65 72 61 | up'', i|t genera|
|00001fc0| 74 65 73 20 53 49 47 48 | 55 50 2e 20 4a 6f 62 20 |tes SIGH|UP. Job |
|00001fd0| 63 6f 6e 74 72 6f 6c 0a | 6e 65 65 64 73 20 6f 6e |control.|needs on|
|00001fe0| 65 20 65 78 74 72 61 20 | 73 69 67 6e 61 6c 20 73 |e extra |signal s|
|00001ff0| 6f 20 74 68 61 74 20 74 | 68 65 20 75 73 65 72 20 |o that t|he user |
|00002000| 63 61 6e 20 74 65 6c 6c | 20 74 68 65 20 63 75 72 |can tell| the cur|
|00002010| 72 65 6e 74 20 70 72 6f | 63 65 73 73 20 74 6f 0a |rent pro|cess to.|
|00002020| 73 74 6f 70 3a 20 6e 61 | 6d 65 6c 79 2c 20 74 68 |stop: na|mely, th|
|00002030| 65 20 73 75 73 70 65 6e | 64 20 63 68 61 72 61 63 |e suspen|d charac|
|00002040| 74 65 72 20 6d 65 6e 74 | 69 6f 6e 65 64 20 61 62 |ter ment|ioned ab|
|00002050| 6f 76 65 20 28 74 79 70 | 69 63 61 6c 6c 79 20 5e |ove (typ|ically ^|
|00002060| 5a 29 2c 0a 77 68 69 63 | 68 20 67 65 6e 65 72 61 |Z),.whic|h genera|
|00002070| 74 65 73 20 53 49 47 54 | 53 54 50 2e 20 4e 6f 74 |tes SIGT|STP. Not|
|00002080| 69 63 65 20 74 68 61 74 | 20 69 66 20 61 20 75 73 |ice that| if a us|
|00002090| 65 72 20 63 6f 75 6c 64 | 20 73 65 74 20 68 69 73 |er could| set his|
|000020a0| 20 74 74 79 27 73 0a 70 | 72 6f 63 65 73 73 20 67 | tty's.p|rocess g|
|000020b0| 72 6f 75 70 20 61 72 62 | 69 74 72 61 72 69 6c 79 |roup arb|itrarily|
|000020c0| 2c 20 68 65 20 63 6f 75 | 6c 64 20 73 65 6e 64 20 |, he cou|ld send |
|000020d0| 61 6c 6c 20 73 6f 72 74 | 73 20 6f 66 20 73 69 67 |all sort|s of sig|
|000020e0| 6e 61 6c 73 20 74 6f 20 | 61 6e 79 0a 70 72 6f 63 |nals to |any.proc|
|000020f0| 65 73 73 65 73 20 69 6e | 20 74 68 6f 73 65 20 70 |esses in| those p|
|00002100| 72 6f 63 65 73 73 20 67 | 72 6f 75 70 73 2e 20 53 |rocess g|roups. S|
|00002110| 6f 20 69 74 20 69 73 20 | 69 6d 70 6f 72 74 61 6e |o it is |importan|
|00002120| 74 20 66 6f 72 20 73 65 | 63 75 72 69 74 79 20 74 |t for se|curity t|
|00002130| 68 61 74 0a 74 74 79 20 | 70 72 6f 63 65 73 73 20 |hat.tty |process |
|00002140| 67 72 6f 75 70 73 20 62 | 65 20 63 6f 6e 74 72 6f |groups b|e contro|
|00002150| 6c 6c 65 64 2e 0a 58 0a | 54 68 65 20 73 75 73 70 |lled..X.|The susp|
|00002160| 65 6e 64 20 63 68 61 72 | 61 63 74 65 72 20 69 73 |end char|acter is|
|00002170| 20 74 68 65 20 66 69 72 | 73 74 20 75 73 65 72 20 | the fir|st user |
|00002180| 69 6e 74 65 72 66 61 63 | 65 20 61 73 70 65 63 74 |interfac|e aspect|
|00002190| 20 6f 66 20 6a 6f 62 20 | 63 6f 6e 74 72 6f 6c 0a | of job |control.|
|000021a0| 6d 65 6e 74 69 6f 6e 65 | 64 20 73 6f 20 66 61 72 |mentione|d so far|
|000021b0| 2e 20 54 79 70 69 63 61 | 6c 6c 79 20 74 68 65 20 |. Typica|lly the |
|000021c0| 70 72 6f 63 65 73 73 65 | 73 20 73 74 6f 70 20 28 |processe|s stop (|
|000021d0| 74 68 6f 75 67 68 20 74 | 68 65 79 20 63 61 6e 20 |though t|hey can |
|000021e0| 63 61 74 63 68 0a 53 49 | 47 54 53 54 50 20 61 6e |catch.SI|GTSTP an|
|000021f0| 64 20 64 6f 20 73 6f 6d | 65 74 68 69 6e 67 20 65 |d do som|ething e|
|00002200| 6c 73 65 29 2e 20 41 20 | 6a 6f 62 2d 63 6f 6e 74 |lse). A |job-cont|
|00002210| 72 6f 6c 20 73 68 65 6c | 6c 20 74 68 65 6e 20 72 |rol shel|l then r|
|00002220| 65 63 65 69 76 65 73 20 | 74 68 65 0a 53 49 47 43 |eceives |the.SIGC|
|00002230| 48 4c 44 20 61 6e 64 2c | 20 77 69 74 68 20 77 61 |HLD and,| with wa|
|00002240| 69 74 32 28 29 2c 20 73 | 65 65 73 20 74 68 61 74 |it2(), s|ees that|
|00002250| 20 69 74 73 20 63 68 69 | 6c 64 72 65 6e 20 68 61 | its chi|ldren ha|
|00002260| 76 65 20 73 74 6f 70 70 | 65 64 2e 20 49 74 20 63 |ve stopp|ed. It c|
|00002270| 61 6e 0a 72 65 70 6f 72 | 74 20 74 68 69 73 20 74 |an.repor|t this t|
|00002280| 6f 20 74 68 65 20 75 73 | 65 72 20 61 6e 64 20 70 |o the us|er and p|
|00002290| 72 65 73 65 6e 74 20 61 | 20 6e 65 77 20 70 72 6f |resent a| new pro|
|000022a0| 6d 70 74 2e 20 54 68 65 | 20 75 73 65 72 20 63 61 |mpt. The| user ca|
|000022b0| 6e 20 74 68 65 6e 0a 73 | 74 61 72 74 20 6d 6f 72 |n then.s|tart mor|
|000022c0| 65 20 70 72 6f 63 65 73 | 73 65 73 2c 20 6f 72 2c |e proces|ses, or,|
|000022d0| 20 77 69 74 68 20 61 6e | 20 60 60 66 67 27 27 20 | with an| ``fg'' |
|000022e0| 28 66 6f 72 65 67 72 6f | 75 6e 64 29 20 63 6f 6d |(foregro|und) com|
|000022f0| 6d 61 6e 64 2c 20 74 65 | 6c 6c 20 74 68 65 0a 73 |mand, te|ll the.s|
|00002300| 68 65 6c 6c 20 74 6f 20 | 73 65 6e 64 20 53 49 47 |hell to |send SIG|
|00002310| 43 4f 4e 54 20 74 6f 20 | 74 68 65 20 63 68 69 6c |CONT to |the chil|
|00002320| 64 72 65 6e 20 73 6f 20 | 74 68 61 74 20 74 68 65 |dren so |that the|
|00002330| 79 20 73 74 61 72 74 20 | 75 70 20 61 67 61 69 6e |y start |up again|
|00002340| 2e 0a 58 0a 50 72 6f 67 | 72 61 6d 73 20 63 61 6e |..X.Prog|rams can|
|00002350| 20 69 6e 73 70 65 63 74 | 20 61 6e 64 20 73 65 74 | inspect| and set|
|00002360| 20 74 68 65 20 73 75 73 | 70 65 6e 64 20 63 68 61 | the sus|pend cha|
|00002370| 72 61 63 74 65 72 20 77 | 69 74 68 20 74 77 6f 20 |racter w|ith two |
|00002380| 6e 65 77 20 74 74 79 0a | 69 6f 63 74 6c 73 3a 20 |new tty.|ioctls: |
|00002390| 54 49 4f 43 47 4c 54 43 | 20 61 6e 64 20 54 49 4f |TIOCGLTC| and TIO|
|000023a0| 43 53 4c 54 43 2c 20 62 | 6f 74 68 20 64 65 66 69 |CSLTC, b|oth defi|
|000023b0| 6e 65 64 20 69 6e 20 3c | 73 79 73 2f 69 6f 63 74 |ned in <|sys/ioct|
|000023c0| 6c 2e 68 3e 2e 20 49 6e | 20 62 6f 74 68 0a 63 61 |l.h>. In| both.ca|
|000023d0| 73 65 73 20 74 68 65 20 | 61 72 67 75 6d 65 6e 74 |ses the |argument|
|000023e0| 20 70 6f 69 6e 74 73 20 | 74 6f 20 61 20 60 60 73 | points |to a ``s|
|000023f0| 74 72 75 63 74 20 6c 74 | 63 68 61 72 73 27 27 20 |truct lt|chars'' |
|00002400| 28 64 65 66 69 6e 65 64 | 20 69 6e 20 74 68 65 20 |(defined| in the |
|00002410| 73 61 6d 65 0a 70 6c 61 | 63 65 29 2c 20 77 68 69 |same.pla|ce), whi|
|00002420| 63 68 20 63 6f 6e 74 61 | 69 6e 73 20 61 20 63 68 |ch conta|ins a ch|
|00002430| 61 72 20 74 5f 73 75 73 | 70 63 20 73 70 65 63 69 |ar t_sus|pc speci|
|00002440| 66 79 69 6e 67 20 74 68 | 65 20 73 75 73 70 65 6e |fying th|e suspen|
|00002450| 64 20 63 68 61 72 61 63 | 74 65 72 2e 0a 58 0a 41 |d charac|ter..X.A|
|00002460| 73 20 61 20 6d 61 74 74 | 65 72 20 6f 66 20 66 61 |s a matt|er of fa|
|00002470| 63 74 2c 20 75 6e 64 65 | 72 20 42 53 44 20 74 68 |ct, unde|r BSD th|
|00002480| 65 72 65 20 61 72 65 20 | 73 65 76 65 72 61 6c 20 |ere are |several |
|00002490| 6f 74 68 65 72 20 6c 6f | 63 61 6c 20 74 65 72 6d |other lo|cal term|
|000024a0| 69 6e 61 6c 0a 63 68 61 | 72 61 63 74 65 72 73 20 |inal.cha|racters |
|000024b0| 28 74 68 61 74 27 73 20 | 77 68 61 74 20 6c 74 63 |(that's |what ltc|
|000024c0| 68 61 72 73 20 73 74 61 | 6e 64 73 20 66 6f 72 29 |hars sta|nds for)|
|000024d0| 2c 20 6e 6f 74 61 62 6c | 79 20 74 5f 64 73 75 73 |, notabl|y t_dsus|
|000024e0| 70 63 2e 20 54 68 65 0a | 64 65 6c 61 79 65 64 20 |pc. The.|delayed |
|000024f0| 73 75 73 70 65 6e 64 20 | 63 68 61 72 61 63 74 65 |suspend |characte|
|00002500| 72 20 28 74 79 70 69 63 | 61 6c 6c 79 20 5e 59 29 |r (typic|ally ^Y)|
|00002510| 20 69 73 20 73 75 70 70 | 6f 73 65 64 20 74 6f 20 | is supp|osed to |
|00002520| 61 63 74 20 6c 69 6b 65 | 20 74 68 65 0a 73 75 73 |act like| the.sus|
|00002530| 70 65 6e 64 20 63 68 61 | 72 61 63 74 65 72 20 62 |pend cha|racter b|
|00002540| 75 74 20 6f 6e 6c 79 20 | 77 68 65 6e 20 61 20 70 |ut only |when a p|
|00002550| 72 6f 63 65 73 73 20 61 | 63 74 75 61 6c 6c 79 20 |rocess a|ctually |
|00002560| 72 65 61 64 73 20 69 74 | 2e 20 48 6f 77 65 76 65 |reads it|. Howeve|
|00002570| 72 2c 0a 73 65 76 65 72 | 61 6c 20 6f 70 65 72 61 |r,.sever|al opera|
|00002580| 74 69 6e 67 20 73 79 73 | 74 65 6d 20 72 65 6c 65 |ting sys|tem rele|
|00002590| 61 73 65 73 20 66 72 6f | 6d 20 53 75 6e 20 73 69 |ases fro|m Sun si|
|000025a0| 6d 70 6c 79 20 64 6f 6e | 27 74 20 64 6f 20 74 68 |mply don|'t do th|
|000025b0| 69 73 2e 20 54 68 65 79 | 0a 70 61 73 73 20 64 73 |is. They|.pass ds|
|000025c0| 75 73 70 20 74 68 72 6f | 75 67 68 20 6c 69 6b 65 |usp thro|ugh like|
|000025d0| 20 61 6e 79 20 6f 74 68 | 65 72 20 63 68 61 72 61 | any oth|er chara|
|000025e0| 63 74 65 72 2e 20 47 69 | 76 65 6e 20 74 68 61 74 |cter. Gi|ven that|
|000025f0| 20 61 6c 6d 6f 73 74 20 | 6e 6f 62 6f 64 79 0a 65 | almost |nobody.e|
|00002600| 76 65 72 20 6e 6f 74 69 | 63 65 73 20 74 68 69 73 |ver noti|ces this|
|00002610| 20 62 75 67 2c 20 6c 65 | 74 20 61 6c 6f 6e 65 20 | bug, le|t alone |
|00002620| 63 6f 6d 70 6c 61 69 6e | 73 20 61 62 6f 75 74 20 |complain|s about |
|00002630| 69 74 2c 20 49 20 64 6f | 6e 27 74 20 74 68 69 6e |it, I do|n't thin|
|00002640| 6b 0a 74 68 65 72 65 27 | 73 20 61 6e 79 20 70 6f |k.there'|s any po|
|00002650| 69 6e 74 20 69 6e 20 62 | 6f 74 68 65 72 69 6e 67 |int in b|othering|
|00002660| 20 74 6f 20 69 6d 70 6c | 65 6d 65 6e 74 20 74 68 | to impl|ement th|
|00002670| 65 20 63 68 61 72 61 63 | 74 65 72 2e 0a 58 0a 58 |e charac|ter..X.X|
|00002680| 0a 58 36 2e 20 49 2f 4f | 2d 67 65 6e 65 72 61 74 |.X6. I/O|-generat|
|00002690| 65 64 20 73 69 67 6e 61 | 6c 73 0a 58 0a 54 68 65 |ed signa|ls.X.The|
|000026a0| 72 65 27 73 20 61 6e 6f | 74 68 65 72 20 73 69 64 |re's ano|ther sid|
|000026b0| 65 20 74 6f 20 74 68 65 | 20 6a 6f 62 20 63 6f 6e |e to the| job con|
|000026c0| 74 72 6f 6c 20 75 73 65 | 72 20 69 6e 74 65 72 66 |trol use|r interf|
|000026d0| 61 63 65 3a 20 6e 61 6d | 65 6c 79 2c 20 73 65 76 |ace: nam|ely, sev|
|000026e0| 65 72 61 6c 0a 70 72 6f | 63 65 73 73 65 73 20 28 |eral.pro|cesses (|
|000026f0| 6f 72 20 70 69 70 65 6c | 69 6e 65 73 2d 2d 2d 69 |or pipel|ines---i|
|00002700| 6e 20 67 65 6e 65 72 61 | 6c 2c 20 60 60 6a 6f 62 |n genera|l, ``job|
|00002710| 73 27 27 29 20 63 61 6e | 20 72 65 61 64 20 61 6e |s'') can| read an|
|00002720| 64 20 77 72 69 74 65 20 | 74 68 65 0a 74 74 79 20 |d write |the.tty |
|00002730| 61 74 20 6f 6e 63 65 2e | 20 54 68 65 20 6a 6f 62 |at once.| The job|
|00002740| 2d 63 6f 6e 74 72 6f 6c | 20 73 68 65 6c 6c 20 70 |-control| shell p|
|00002750| 6c 61 63 65 73 20 65 61 | 63 68 20 70 69 70 65 6c |laces ea|ch pipel|
|00002760| 69 6e 65 20 69 6e 74 6f | 20 61 20 73 65 70 61 72 |ine into| a separ|
|00002770| 61 74 65 0a 70 72 6f 63 | 65 73 73 20 67 72 6f 75 |ate.proc|ess grou|
|00002780| 70 2c 20 61 6e 64 20 77 | 68 65 6e 20 61 6e 79 20 |p, and w|hen any |
|00002790| 6a 6f 62 20 65 78 63 65 | 70 74 20 74 68 65 20 66 |job exce|pt the f|
|000027a0| 6f 72 65 67 72 6f 75 6e | 64 20 6a 6f 62 20 72 65 |oregroun|d job re|
|000027b0| 61 64 73 20 66 72 6f 6d | 20 74 68 65 0a 74 74 79 |ads from| the.tty|
|000027c0| 2c 20 69 74 20 69 73 20 | 73 74 6f 70 70 65 64 20 |, it is |stopped |
|000027d0| 75 6e 74 69 6c 20 74 68 | 65 20 75 73 65 72 20 64 |until th|e user d|
|000027e0| 65 63 69 64 65 73 20 74 | 6f 20 67 69 76 65 20 69 |ecides t|o give i|
|000027f0| 74 20 69 6e 70 75 74 2e | 20 54 68 69 73 20 69 73 |t input.| This is|
|00002800| 20 6d 75 63 68 0a 6d 6f | 72 65 20 66 6c 65 78 69 | much.mo|re flexi|
|00002810| 62 6c 65 20 74 68 61 6e | 20 63 75 74 74 69 6e 67 |ble than| cutting|
|00002820| 20 62 61 63 6b 67 72 6f | 75 6e 64 20 70 72 6f 63 | backgro|und proc|
|00002830| 65 73 73 65 73 20 6f 66 | 66 20 66 72 6f 6d 20 74 |esses of|f from t|
|00002840| 68 65 20 74 74 79 0a 70 | 65 72 6d 61 6e 65 6e 74 |he tty.p|ermanent|
|00002850| 6c 79 2c 20 61 73 20 6e | 6f 6e 2d 6a 6f 62 2d 63 |ly, as n|on-job-c|
|00002860| 6f 6e 74 72 6f 6c 20 73 | 68 65 6c 6c 73 20 64 6f |ontrol s|hells do|
|00002870| 2e 0a 58 0a 4d 6f 72 65 | 20 70 72 65 63 69 73 65 |..X.More| precise|
|00002880| 6c 79 2c 20 69 66 20 61 | 20 70 72 6f 63 65 73 73 |ly, if a| process|
|00002890| 20 72 65 61 64 73 20 66 | 72 6f 6d 20 61 20 74 74 | reads f|rom a tt|
|000028a0| 79 2c 20 61 6e 64 20 69 | 74 73 20 70 72 6f 63 65 |y, and i|ts proce|
|000028b0| 73 73 20 67 72 6f 75 70 | 20 69 73 0a 6e 6f 74 20 |ss group| is.not |
|000028c0| 74 68 65 20 66 6f 72 65 | 67 72 6f 75 6e 64 20 70 |the fore|ground p|
|000028d0| 72 6f 63 65 73 73 20 67 | 72 6f 75 70 20 6f 66 20 |rocess g|roup of |
|000028e0| 74 68 65 20 74 74 79 2c | 20 74 68 65 6e 20 69 74 |the tty,| then it|
|000028f0| 73 20 70 72 6f 63 65 73 | 73 20 67 72 6f 75 70 20 |s proces|s group |
|00002900| 69 73 0a 73 65 6e 74 20 | 61 20 53 49 47 54 54 49 |is.sent |a SIGTTI|
|00002910| 4e 20 73 69 67 6e 61 6c | 2e 20 41 73 20 61 6e 20 |N signal|. As an |
|00002920| 65 78 63 65 70 74 69 6f | 6e 2c 20 69 66 20 74 68 |exceptio|n, if th|
|00002930| 61 74 20 70 72 6f 63 65 | 73 73 20 69 73 20 62 6c |at proce|ss is bl|
|00002940| 6f 63 6b 69 6e 67 20 6f | 72 0a 69 67 6e 6f 72 69 |ocking o|r.ignori|
|00002950| 6e 67 20 53 49 47 54 54 | 49 4e 2c 20 6e 6f 20 73 |ng SIGTT|IN, no s|
|00002960| 69 67 6e 61 6c 20 69 73 | 20 67 65 6e 65 72 61 74 |ignal is| generat|
|00002970| 65 64 2e 20 49 6e 73 74 | 65 61 64 2c 20 74 68 65 |ed. Inst|ead, the|
|00002980| 20 72 65 61 64 20 72 65 | 74 75 72 6e 73 20 2d 31 | read re|turns -1|
|00002990| 0a 77 69 74 68 20 65 72 | 72 6e 6f 20 6f 66 20 45 |.with er|rno of E|
|000029a0| 49 4f 2e 20 60 60 52 65 | 61 64 69 6e 67 27 27 20 |IO. ``Re|ading'' |
|000029b0| 68 65 72 65 20 69 6e 63 | 6c 75 64 65 73 20 6f 6e |here inc|ludes on|
|000029c0| 6c 79 20 72 65 61 64 28 | 29 2c 20 6e 6f 74 20 74 |ly read(|), not t|
|000029d0| 68 65 0a 76 61 72 69 6f | 75 73 20 74 74 79 20 69 |he.vario|us tty i|
|000029e0| 6f 63 74 6c 73 20 77 68 | 69 63 68 20 69 6e 73 70 |octls wh|ich insp|
|000029f0| 65 63 74 20 74 74 79 20 | 73 74 72 75 63 74 75 72 |ect tty |structur|
|00002a00| 65 73 3b 20 77 68 69 6c | 65 20 74 68 65 72 65 20 |es; whil|e there |
|00002a10| 61 72 65 20 73 6f 6d 65 | 0a 62 65 6e 65 66 69 74 |are some|.benefit|
|00002a20| 73 20 6f 66 20 67 65 6e | 65 72 61 74 69 6e 67 20 |s of gen|erating |
|00002a30| 53 49 47 54 54 49 4e 20 | 66 6f 72 20 74 68 65 20 |SIGTTIN |for the |
|00002a40| 6c 61 74 74 65 72 2c 20 | 74 68 69 73 20 74 75 72 |latter, |this tur|
|00002a50| 6e 73 20 6f 75 74 20 74 | 6f 20 62 65 20 74 6f 6f |ns out t|o be too|
|00002a60| 0a 72 65 73 74 72 69 63 | 74 69 76 65 20 66 6f 72 |.restric|tive for|
|00002a70| 20 6d 61 6e 79 20 61 70 | 70 6c 69 63 61 74 69 6f | many ap|plicatio|
|00002a80| 6e 73 2e 20 28 54 68 65 | 72 65 20 69 73 20 61 6e |ns. (The|re is an|
|00002a90| 20 69 6f 63 74 6c 2c 20 | 54 49 4f 43 53 54 49 2c | ioctl, |TIOCSTI,|
|00002aa0| 20 77 68 69 63 68 20 69 | 73 0a 61 6c 73 6f 20 6c | which i|s.also l|
|00002ab0| 75 6d 70 65 64 20 77 69 | 74 68 20 60 60 72 65 61 |umped wi|th ``rea|
|00002ac0| 64 69 6e 67 2c 27 27 20 | 62 75 74 20 61 20 66 75 |ding,'' |but a fu|
|00002ad0| 6c 6c 20 64 69 73 63 75 | 73 73 69 6f 6e 20 6f 66 |ll discu|ssion of|
|00002ae0| 20 54 49 4f 43 53 54 49 | 20 77 6f 75 6c 64 20 62 | TIOCSTI| would b|
|00002af0| 65 0a 74 6f 6f 20 6c 6f | 6e 67 20 66 6f 72 20 74 |e.too lo|ng for t|
|00002b00| 68 69 73 20 70 61 70 65 | 72 2e 20 49 74 27 73 20 |his pape|r. It's |
|00002b10| 6e 6f 74 20 61 6e 20 69 | 6d 70 6f 72 74 61 6e 74 |not an i|mportant|
|00002b20| 20 65 6e 6f 75 67 68 20 | 69 6f 63 74 6c 20 74 6f | enough |ioctl to|
|00002b30| 20 62 6f 74 68 65 72 0a | 77 69 74 68 2e 29 0a 58 | bother.|with.).X|
|00002b40| 0a 49 66 20 61 20 70 72 | 6f 63 65 73 73 20 77 72 |.If a pr|ocess wr|
|00002b50| 69 74 65 73 20 74 6f 20 | 61 20 74 74 79 2c 20 61 |ites to |a tty, a|
|00002b60| 6e 64 20 69 74 73 20 70 | 72 6f 63 65 73 73 20 67 |nd its p|rocess g|
|00002b70| 72 6f 75 70 20 69 73 20 | 6e 6f 74 20 74 68 65 0a |roup is |not the.|
|00002b80| 66 6f 72 65 67 72 6f 75 | 6e 64 20 70 72 6f 63 65 |foregrou|nd proce|
|00002b90| 73 73 20 67 72 6f 75 70 | 20 6f 66 20 74 68 65 20 |ss group| of the |
|00002ba0| 74 74 79 2c 20 74 68 65 | 6e 20 69 74 73 20 70 72 |tty, the|n its pr|
|00002bb0| 6f 63 65 73 73 20 67 72 | 6f 75 70 20 69 73 20 73 |ocess gr|oup is s|
|00002bc0| 65 6e 74 20 61 0a 53 49 | 47 54 54 4f 55 20 73 69 |ent a.SI|GTTOU si|
|00002bd0| 67 6e 61 6c 2e 20 41 73 | 20 61 6e 20 65 78 63 65 |gnal. As| an exce|
|00002be0| 70 74 69 6f 6e 2c 20 69 | 66 20 74 68 61 74 20 70 |ption, i|f that p|
|00002bf0| 72 6f 63 65 73 73 20 69 | 73 20 62 6c 6f 63 6b 69 |rocess i|s blocki|
|00002c00| 6e 67 20 6f 72 20 69 67 | 6e 6f 72 69 6e 67 0a 53 |ng or ig|noring.S|
|00002c10| 49 47 54 54 4f 55 2c 20 | 6e 6f 20 73 69 67 6e 61 |IGTTOU, |no signa|
|00002c20| 6c 20 69 73 20 67 65 6e | 65 72 61 74 65 64 20 61 |l is gen|erated a|
|00002c30| 6e 64 20 69 74 20 69 73 | 20 61 6c 6c 6f 77 65 64 |nd it is| allowed|
|00002c40| 20 74 6f 20 70 72 6f 64 | 75 63 65 20 6f 75 74 70 | to prod|uce outp|
|00002c50| 75 74 2e 0a 54 68 69 73 | 20 74 69 6d 65 2c 20 60 |ut..This| time, `|
|00002c60| 60 77 72 69 74 65 27 27 | 20 69 6e 63 6c 75 64 65 |`write''| include|
|00002c70| 73 20 6e 6f 74 20 6f 6e | 6c 79 20 77 72 69 74 65 |s not on|ly write|
|00002c80| 28 29 20 62 75 74 20 61 | 6c 73 6f 20 61 6e 79 20 |() but a|lso any |
|00002c90| 6f 74 68 65 72 0a 6f 70 | 65 72 61 74 69 6f 6e 73 |other.op|erations|
|00002ca0| 20 77 68 69 63 68 20 61 | 66 66 65 63 74 20 74 68 | which a|ffect th|
|00002cb0| 65 20 74 74 79 20 69 6e | 20 61 6e 79 20 77 61 79 |e tty in| any way|
|00002cc0| 2e 20 28 55 6e 64 65 72 | 20 42 53 44 20 74 68 65 |. (Under| BSD the|
|00002cd0| 72 65 20 69 73 20 61 20 | 74 74 79 0a 6d 6f 64 65 |re is a |tty.mode|
|00002ce0| 2c 20 4c 54 4f 53 54 4f | 50 2c 20 77 68 69 63 68 |, LTOSTO|P, which|
|00002cf0| 20 77 68 65 6e 20 64 69 | 73 61 62 6c 65 64 20 74 | when di|sabled t|
|00002d00| 75 72 6e 73 20 6f 66 66 | 20 54 54 4f 55 20 66 6f |urns off| TTOU fo|
|00002d10| 72 20 77 72 69 74 65 28 | 29 20 62 75 74 20 6e 6f |r write(|) but no|
|00002d20| 74 0a 66 6f 72 20 6f 74 | 68 65 72 20 6f 70 65 72 |t.for ot|her oper|
|00002d30| 61 74 69 6f 6e 73 2e 20 | 54 68 69 73 20 69 73 20 |ations. |This is |
|00002d40| 6e 6f 74 20 61 62 73 6f | 6c 75 74 65 6c 79 20 6e |not abso|lutely n|
|00002d50| 65 63 65 73 73 61 72 79 | 2c 20 62 75 74 20 69 66 |ecessary|, but if|
|00002d60| 20 79 6f 75 20 68 61 76 | 65 0a 61 6e 79 20 66 72 | you hav|e.any fr|
|00002d70| 65 65 20 74 69 6d 65 20 | 79 6f 75 20 73 68 6f 75 |ee time |you shou|
|00002d80| 6c 64 20 69 6d 70 6c 65 | 6d 65 6e 74 20 73 74 74 |ld imple|ment stt|
|00002d90| 79 20 74 6f 73 74 6f 70 | 20 74 6f 20 74 75 72 6e |y tostop| to turn|
|00002da0| 20 4c 54 4f 53 54 4f 50 | 20 6f 6e 20 61 6e 64 0a | LTOSTOP| on and.|
|00002db0| 73 74 74 79 20 2d 74 6f | 73 74 6f 70 20 74 6f 20 |stty -to|stop to |
|00002dc0| 74 75 72 6e 20 69 74 20 | 6f 66 66 2e 20 54 68 65 |turn it |off. The|
|00002dd0| 20 69 6e 74 65 72 6e 61 | 6c 20 69 6e 74 65 72 66 | interna|l interf|
|00002de0| 61 63 65 20 69 73 20 75 | 6e 69 6d 70 6f 72 74 61 |ace is u|nimporta|
|00002df0| 6e 74 20 61 73 0a 6c 6f | 6e 67 20 61 73 20 74 68 |nt as.lo|ng as th|
|00002e00| 65 20 75 73 65 72 20 63 | 61 6e 20 73 65 6c 65 63 |e user c|an selec|
|00002e10| 74 20 68 69 73 20 66 61 | 76 6f 72 69 74 65 20 62 |t his fa|vorite b|
|00002e20| 65 68 61 76 69 6f 72 2e | 29 0a 58 0a 4e 6f 6e 65 |ehavior.|).X.None|
|00002e30| 20 6f 66 20 74 68 65 20 | 61 62 6f 76 65 20 61 70 | of the |above ap|
|00002e40| 70 6c 79 20 74 6f 20 6f | 70 65 72 61 74 69 6f 6e |ply to o|peration|
|00002e50| 73 20 62 79 20 61 20 70 | 72 6f 63 65 73 73 20 69 |s by a p|rocess i|
|00002e60| 6e 20 70 72 6f 63 65 73 | 73 20 67 72 6f 75 70 20 |n proces|s group |
|00002e70| 30 2e 0a 50 72 6f 63 65 | 73 73 20 67 72 6f 75 70 |0..Proce|ss group|
|00002e80| 20 30 20 6d 75 73 74 20 | 6e 65 76 65 72 2c 20 65 | 0 must |never, e|
|00002e90| 76 65 72 2c 20 62 65 20 | 73 65 6e 74 20 49 2f 4f |ver, be |sent I/O|
|00002ea0| 2d 67 65 6e 65 72 61 74 | 65 64 20 73 69 67 6e 61 |-generat|ed signa|
|00002eb0| 6c 73 2e 20 54 68 65 0a | 73 69 6d 70 6c 65 73 74 |ls. The.|simplest|
|00002ec0| 20 63 6f 75 72 73 65 20 | 6f 66 20 61 63 74 69 6f | course |of actio|
|00002ed0| 6e 20 68 65 72 65 20 69 | 73 20 74 6f 20 6c 65 74 |n here i|s to let|
|00002ee0| 20 61 6c 6c 20 6f 70 65 | 72 61 74 69 6f 6e 73 20 | all ope|rations |
|00002ef0| 66 72 6f 6d 20 70 72 6f | 63 65 73 73 0a 67 72 6f |from pro|cess.gro|
|00002f00| 75 70 20 30 20 73 75 63 | 63 65 65 64 2e 20 28 57 |up 0 suc|ceed. (W|
|00002f10| 68 61 74 20 61 63 74 75 | 61 6c 6c 79 20 68 61 70 |hat actu|ally hap|
|00002f20| 70 65 6e 73 20 69 6e 20 | 74 68 69 73 20 63 61 73 |pens in |this cas|
|00002f30| 65 20 69 73 6e 27 74 20 | 74 6f 6f 0a 69 6d 70 6f |e isn't |too.impo|
|00002f40| 72 74 61 6e 74 2c 20 61 | 73 20 6c 6f 6e 67 20 61 |rtant, a|s long a|
|00002f50| 73 20 70 72 6f 63 65 73 | 73 65 73 20 6c 69 6b 65 |s proces|ses like|
|00002f60| 20 67 65 74 74 79 20 63 | 61 6e 20 6f 70 65 6e 20 | getty c|an open |
|00002f70| 61 20 74 74 79 20 61 6e | 64 20 73 74 61 72 74 0a |a tty an|d start.|
|00002f80| 70 72 6f 67 72 61 6d 73 | 20 6f 6e 20 74 68 65 20 |programs| on the |
|00002f90| 74 74 79 2e 20 4d 6f 73 | 74 20 42 53 44 2d 64 65 |tty. Mos|t BSD-de|
|00002fa0| 72 69 76 65 64 20 73 79 | 73 74 65 6d 73 20 73 65 |rived sy|stems se|
|00002fb0| 74 20 70 72 6f 63 65 73 | 73 20 67 72 6f 75 70 20 |t proces|s group |
|00002fc0| 74 6f 20 70 69 64 0a 77 | 68 65 6e 20 61 20 70 72 |to pid.w|hen a pr|
|00002fd0| 6f 63 65 73 73 20 69 6e | 20 70 72 6f 63 65 73 73 |ocess in| process|
|00002fe0| 20 67 72 6f 75 70 20 30 | 20 6f 70 65 6e 73 20 61 | group 0| opens a|
|00002ff0| 20 74 74 79 3b 20 74 68 | 69 73 20 62 65 68 61 76 | tty; th|is behav|
|00003000| 69 6f 72 20 69 73 20 6e | 6f 74 0a 6e 65 63 65 73 |ior is n|ot.neces|
|00003010| 73 61 72 79 2e 20 4e 6f | 74 65 20 74 68 61 74 20 |sary. No|te that |
|00003020| 69 66 20 61 20 70 72 6f | 63 65 73 73 20 69 6e 20 |if a pro|cess in |
|00003030| 70 72 6f 63 65 73 73 20 | 67 72 6f 75 70 20 30 20 |process |group 0 |
|00003040| 72 65 61 64 73 20 66 72 | 6f 6d 20 61 20 74 74 79 |reads fr|om a tty|
|00003050| 0a 77 68 69 6c 65 20 61 | 20 73 68 65 6c 6c 20 69 |.while a| shell i|
|00003060| 73 20 73 74 69 6c 6c 20 | 72 65 61 64 69 6e 67 20 |s still |reading |
|00003070| 66 72 6f 6d 20 69 74 2c | 20 74 68 65 20 74 77 6f |from it,| the two|
|00003080| 20 72 65 61 64 28 29 73 | 20 77 69 6c 6c 20 63 6f | read()s| will co|
|00003090| 6d 70 65 74 65 20 66 6f | 72 0a 74 65 72 6d 69 6e |mpete fo|r.termin|
|000030a0| 61 6c 20 69 6e 70 75 74 | 2e 29 0a 58 0a 4e 6f 74 |al input|.).X.Not|
|000030b0| 69 63 65 20 74 68 61 74 | 20 69 66 20 61 20 70 72 |ice that| if a pr|
|000030c0| 6f 63 65 73 73 20 63 61 | 6e 20 6a 6f 69 6e 20 61 |ocess ca|n join a|
|000030d0| 6e 20 61 72 62 69 74 72 | 61 72 79 20 70 72 6f 63 |n arbitr|ary proc|
|000030e0| 65 73 73 20 67 72 6f 75 | 70 2c 20 69 74 20 63 61 |ess grou|p, it ca|
|000030f0| 6e 0a 63 61 75 73 65 20 | 53 49 47 54 54 4f 55 20 |n.cause |SIGTTOU |
|00003100| 61 6e 64 20 53 49 47 54 | 54 49 4e 20 74 6f 20 62 |and SIGT|TIN to b|
|00003110| 65 20 73 65 6e 74 20 74 | 6f 20 6f 74 68 65 72 20 |e sent t|o other |
|00003120| 70 72 6f 63 65 73 73 2e | 20 53 6f 20 69 74 27 73 |process.| So it's|
|00003130| 20 69 6d 70 6f 72 74 61 | 6e 74 0a 66 6f 72 20 73 | importa|nt.for s|
|00003140| 65 63 75 72 69 74 79 20 | 74 68 61 74 20 70 72 6f |ecurity |that pro|
|00003150| 63 65 73 73 65 73 27 20 | 70 72 6f 63 65 73 73 20 |cesses' |process |
|00003160| 67 72 6f 75 70 73 20 62 | 65 20 63 6f 6e 74 72 6f |groups b|e contro|
|00003170| 6c 6c 65 64 2e 0a 58 0a | 42 65 20 63 61 72 65 66 |lled..X.|Be caref|
|00003180| 75 6c 20 69 6e 20 69 6d | 70 6c 65 6d 65 6e 74 69 |ul in im|plementi|
|00003190| 6e 67 20 49 2f 4f 2d 67 | 65 6e 65 72 61 74 65 64 |ng I/O-g|enerated|
|000031a0| 20 73 69 67 6e 61 6c 73 | 20 74 68 61 74 20 79 6f | signals| that yo|
|000031b0| 75 20 74 65 73 74 0a 72 | 65 70 65 61 74 65 64 6c |u test.r|epeatedl|
|000031c0| 79 20 66 6f 72 20 74 68 | 65 20 72 69 67 68 74 20 |y for th|e right |
|000031d0| 70 72 6f 63 65 73 73 20 | 67 72 6f 75 70 2e 20 54 |process |group. T|
|000031e0| 68 65 20 70 72 6f 63 65 | 73 73 20 63 6f 75 6c 64 |he proce|ss could|
|000031f0| 20 65 61 73 69 6c 79 20 | 72 65 63 65 69 76 65 0a | easily |receive.|
|00003200| 53 49 47 43 4f 4e 54 20 | 77 68 69 6c 65 20 74 68 |SIGCONT |while th|
|00003210| 65 20 74 74 79 20 69 73 | 20 69 6e 20 61 20 64 69 |e tty is| in a di|
|00003220| 66 66 65 72 65 6e 74 20 | 67 72 6f 75 70 2e 20 49 |fferent |group. I|
|00003230| 6e 20 74 68 61 74 20 63 | 61 73 65 20 69 74 20 73 |n that c|ase it s|
|00003240| 68 6f 75 6c 64 0a 69 6d | 6d 65 64 69 61 74 65 6c |hould.im|mediatel|
|00003250| 79 20 73 74 6f 70 20 74 | 68 65 20 70 72 6f 63 65 |y stop t|he proce|
|00003260| 73 73 20 67 72 6f 75 70 | 20 61 67 61 69 6e 20 28 |ss group| again (|
|00003270| 77 69 74 68 6f 75 74 20 | 65 76 65 6e 20 65 78 65 |without |even exe|
|00003280| 63 75 74 69 6e 67 20 61 | 0a 53 49 47 43 4f 4e 54 |cuting a|.SIGCONT|
|00003290| 20 68 61 6e 64 6c 65 72 | 21 29 2c 20 67 65 6e 65 | handler|!), gene|
|000032a0| 72 61 74 65 20 61 6e 6f | 74 68 65 72 20 53 49 47 |rate ano|ther SIG|
|000032b0| 43 48 4c 44 2c 20 61 6e | 64 20 77 61 69 74 20 66 |CHLD, an|d wait f|
|000032c0| 6f 72 20 74 68 65 20 6e | 65 78 74 0a 53 49 47 43 |or the n|ext.SIGC|
|000032d0| 4f 4e 54 2e 20 54 68 69 | 73 20 63 61 6e 20 72 65 |ONT. Thi|s can re|
|000032e0| 70 65 61 74 20 61 6e 79 | 20 6e 75 6d 62 65 72 20 |peat any| number |
|000032f0| 6f 66 20 74 69 6d 65 73 | 2e 20 4f 6e 6c 79 20 77 |of times|. Only w|
|00003300| 68 65 6e 20 74 68 65 20 | 74 74 79 20 69 73 20 69 |hen the |tty is i|
|00003310| 6e 0a 74 68 65 20 72 69 | 67 68 74 20 70 72 6f 63 |n.the ri|ght proc|
|00003320| 65 73 73 20 67 72 6f 75 | 70 20 73 68 6f 75 6c 64 |ess grou|p should|
|00003330| 20 74 68 65 20 6f 70 65 | 72 61 74 69 6f 6e 20 73 | the ope|ration s|
|00003340| 75 63 63 65 65 64 2e 0a | 58 0a 58 0a 58 37 2e 20 |ucceed..|X.X.X7. |
|00003350| 41 20 6e 65 77 2c 20 73 | 65 63 75 72 65 2c 20 73 |A new, s|ecure, s|
|00003360| 69 6d 70 6c 65 20 6a 6f | 62 20 63 6f 6e 74 72 6f |imple jo|b contro|
|00003370| 6c 20 70 72 6f 67 72 61 | 6d 6d 69 6e 67 20 69 6e |l progra|mming in|
|00003380| 74 65 72 66 61 63 65 0a | 58 0a 54 68 65 20 70 72 |terface.|X.The pr|
|00003390| 6f 63 65 73 73 20 67 72 | 6f 75 70 20 63 61 6c 6c |ocess gr|oup call|
|000033a0| 73 20 64 65 73 63 72 69 | 62 65 64 20 69 6e 20 74 |s descri|bed in t|
|000033b0| 68 69 73 20 73 65 63 74 | 69 6f 6e 20 61 72 65 2c |his sect|ion are,|
|000033c0| 20 75 6e 6c 69 6b 65 20 | 74 68 65 20 6a 6f 62 0a | unlike |the job.|
|000033d0| 63 6f 6e 74 72 6f 6c 20 | 66 65 61 74 75 72 65 73 |control |features|
|000033e0| 20 64 65 73 63 72 69 62 | 65 64 20 69 6e 20 73 65 | describ|ed in se|
|000033f0| 63 74 69 6f 6e 73 20 32 | 20 74 68 72 6f 75 67 68 |ctions 2| through|
|00003400| 20 36 2c 20 6e 6f 74 20 | 70 61 72 74 20 6f 66 20 | 6, not |part of |
|00003410| 42 53 44 2c 0a 74 68 6f | 75 67 68 20 74 68 65 79 |BSD,.tho|ugh they|
|00003420| 20 64 6f 20 6e 6f 74 20 | 69 6e 74 65 72 66 65 72 | do not |interfer|
|00003430| 65 20 77 69 74 68 20 42 | 53 44 2e 20 54 68 65 72 |e with B|SD. Ther|
|00003440| 65 20 61 72 65 20 61 20 | 74 6f 74 61 6c 20 6f 66 |e are a |total of|
|00003450| 20 74 68 72 65 65 20 63 | 61 6c 6c 73 0a 77 68 69 | three c|alls.whi|
|00003460| 63 68 20 6d 61 6e 69 70 | 75 6c 61 74 65 20 70 72 |ch manip|ulate pr|
|00003470| 6f 63 65 73 73 20 67 72 | 6f 75 70 73 3a 20 74 63 |ocess gr|oups: tc|
|00003480| 6e 65 77 70 67 72 70 28 | 29 2c 20 73 65 74 74 70 |newpgrp(|), settp|
|00003490| 67 72 70 28 29 2c 20 74 | 63 74 70 67 72 70 28 29 |grp(), t|ctpgrp()|
|000034a0| 2e 0a 54 68 72 6f 75 67 | 68 6f 75 74 20 74 68 69 |..Throug|hout thi|
|000034b0| 73 20 73 65 63 74 69 6f | 6e 2c 20 66 64 74 74 79 |s sectio|n, fdtty|
|000034c0| 20 69 73 20 61 20 66 69 | 6c 65 20 64 65 73 63 72 | is a fi|le descr|
|000034d0| 69 70 74 6f 72 20 70 6f | 69 6e 74 69 6e 67 20 74 |iptor po|inting t|
|000034e0| 6f 20 61 0a 74 65 72 6d | 69 6e 61 6c 2e 0a 58 0a |o a.term|inal..X.|
|000034f0| 49 66 20 66 64 74 74 79 | 20 68 61 73 20 77 72 69 |If fdtty| has wri|
|00003500| 74 65 20 61 63 63 65 73 | 73 2c 20 74 63 6e 65 77 |te acces|s, tcnew|
|00003510| 70 67 72 70 28 66 64 74 | 74 79 29 20 73 68 6f 75 |pgrp(fdt|ty) shou|
|00003520| 6c 64 20 61 6c 6c 6f 63 | 61 74 65 20 61 6e 20 75 |ld alloc|ate an u|
|00003530| 6e 75 73 65 64 0a 70 72 | 6f 63 65 73 73 20 67 72 |nused.pr|ocess gr|
|00003540| 6f 75 70 20 61 6e 64 20 | 73 65 74 20 74 68 65 20 |oup and |set the |
|00003550| 74 65 72 6d 69 6e 61 6c | 27 73 20 66 6f 72 65 67 |terminal|'s foreg|
|00003560| 72 6f 75 6e 64 20 70 72 | 6f 63 65 73 73 20 67 72 |round pr|ocess gr|
|00003570| 6f 75 70 20 74 6f 20 74 | 68 61 74 0a 6e 65 77 20 |oup to t|hat.new |
|00003580| 70 72 6f 63 65 73 73 20 | 67 72 6f 75 70 2e 20 54 |process |group. T|
|00003590| 68 69 73 20 69 73 20 61 | 20 77 72 69 74 65 20 6f |his is a| write o|
|000035a0| 70 65 72 61 74 69 6f 6e | 20 61 6e 64 20 73 68 6f |peration| and sho|
|000035b0| 75 6c 64 20 70 72 6f 64 | 75 63 65 20 53 49 47 54 |uld prod|uce SIGT|
|000035c0| 54 4f 55 0a 69 66 20 74 | 68 69 73 20 70 72 6f 63 |TOU.if t|his proc|
|000035d0| 65 73 73 20 69 73 20 6e | 6f 74 20 69 6e 20 74 68 |ess is n|ot in th|
|000035e0| 65 20 66 6f 72 65 67 72 | 6f 75 6e 64 20 28 61 6e |e foregr|ound (an|
|000035f0| 64 20 69 73 20 6e 6f 74 | 20 69 67 6e 6f 72 69 6e |d is not| ignorin|
|00003600| 67 20 74 68 65 0a 73 69 | 67 6e 61 6c 2c 20 65 74 |g the.si|gnal, et|
|00003610| 63 2e 29 2e 20 74 63 6e | 65 77 70 67 72 70 20 72 |c.). tcn|ewpgrp r|
|00003620| 65 74 75 72 6e 73 20 30 | 20 6f 6e 20 73 75 63 63 |eturns 0| on succ|
|00003630| 65 73 73 2c 20 2d 31 20 | 77 69 74 68 20 65 72 72 |ess, -1 |with err|
|00003640| 6e 6f 20 45 4e 4f 54 54 | 59 20 69 66 0a 66 64 74 |no ENOTT|Y if.fdt|
|00003650| 74 79 20 69 73 20 6e 6f | 74 20 61 20 74 65 72 6d |ty is no|t a term|
|00003660| 69 6e 61 6c 2c 20 2d 31 | 20 77 69 74 68 20 65 72 |inal, -1| with er|
|00003670| 72 6e 6f 20 45 42 41 44 | 46 20 69 66 20 66 64 74 |rno EBAD|F if fdt|
|00003680| 74 79 20 69 73 20 6e 6f | 74 20 6f 70 65 6e 20 66 |ty is no|t open f|
|00003690| 6f 72 0a 77 72 69 74 69 | 6e 67 2e 0a 58 0a 49 66 |or.writi|ng..X.If|
|000036a0| 20 66 64 74 74 79 20 68 | 61 73 20 72 65 61 64 20 | fdtty h|as read |
|000036b0| 61 63 63 65 73 73 2c 20 | 73 65 74 74 70 67 72 70 |access, |settpgrp|
|000036c0| 28 66 64 74 74 79 29 20 | 73 68 6f 75 6c 64 20 73 |(fdtty) |should s|
|000036d0| 65 74 20 74 68 69 73 20 | 70 72 6f 63 65 73 73 27 |et this |process'|
|000036e0| 73 0a 70 72 6f 63 65 73 | 73 20 67 72 6f 75 70 20 |s.proces|s group |
|000036f0| 74 6f 20 74 68 65 20 66 | 6f 72 65 67 72 6f 75 6e |to the f|oregroun|
|00003700| 64 20 70 72 6f 63 65 73 | 73 20 67 72 6f 75 70 20 |d proces|s group |
|00003710| 6f 66 20 74 68 65 20 74 | 65 72 6d 69 6e 61 6c 2e |of the t|erminal.|
|00003720| 20 41 73 20 61 0a 73 70 | 65 63 69 61 6c 20 63 61 | As a.sp|ecial ca|
|00003730| 73 65 2c 20 73 65 74 74 | 70 67 72 70 28 2d 31 29 |se, sett|pgrp(-1)|
|00003740| 20 73 65 74 73 20 74 68 | 69 73 20 70 72 6f 63 65 | sets th|is proce|
|00003750| 73 73 27 73 20 70 72 6f | 63 65 73 73 20 67 72 6f |ss's pro|cess gro|
|00003760| 75 70 20 74 6f 20 30 2c | 20 73 6f 0a 74 68 61 74 |up to 0,| so.that|
|00003770| 20 69 74 20 69 73 20 65 | 78 65 6d 70 74 20 66 72 | it is e|xempt fr|
|00003780| 6f 6d 20 6a 6f 62 20 63 | 6f 6e 74 72 6f 6c 2e 20 |om job c|ontrol. |
|00003790| 54 68 65 20 6c 61 74 74 | 65 72 20 69 73 20 72 65 |The latt|er is re|
|000037a0| 64 75 6e 64 61 6e 74 2d | 2d 2d 61 20 70 72 6f 63 |dundant-|--a proc|
|000037b0| 65 73 73 0a 63 61 6e 20 | 6a 75 73 74 20 61 73 20 |ess.can |just as |
|000037c0| 65 61 73 69 6c 79 20 63 | 72 65 61 74 65 20 61 20 |easily c|reate a |
|000037d0| 70 72 6f 63 65 73 73 20 | 67 72 6f 75 70 20 66 6f |process |group fo|
|000037e0| 72 20 69 74 73 65 6c 66 | 2c 20 66 6f 72 6b 2c 20 |r itself|, fork, |
|000037f0| 61 6e 64 20 68 69 64 65 | 20 74 68 65 0a 63 68 69 |and hide| the.chi|
|00003800| 6c 64 20 61 77 61 79 20 | 69 6e 73 69 64 65 20 74 |ld away |inside t|
|00003810| 68 61 74 20 67 72 6f 75 | 70 2d 2d 2d 62 75 74 20 |hat grou|p---but |
|00003820| 63 6f 6e 76 65 6e 69 65 | 6e 74 2e 20 73 65 74 74 |convenie|nt. sett|
|00003830| 70 67 72 70 20 72 65 74 | 75 72 6e 73 20 30 20 6f |pgrp ret|urns 0 o|
|00003840| 6e 0a 73 75 63 63 65 73 | 73 2c 20 2d 31 20 77 69 |n.succes|s, -1 wi|
|00003850| 74 68 20 65 72 72 6e 6f | 20 45 4e 4f 54 54 59 20 |th errno| ENOTTY |
|00003860| 69 66 20 66 64 74 74 79 | 20 69 73 20 6e 6f 74 20 |if fdtty| is not |
|00003870| 2d 31 20 61 6e 64 20 6e | 6f 74 20 61 20 74 65 72 |-1 and n|ot a ter|
|00003880| 6d 69 6e 61 6c 2c 20 2d | 31 0a 77 69 74 68 20 65 |minal, -|1.with e|
|00003890| 72 72 6e 6f 20 45 42 41 | 44 46 20 69 66 20 66 64 |rrno EBA|DF if fd|
|000038a0| 74 74 79 20 69 73 20 6e | 6f 74 20 6f 70 65 6e 20 |tty is n|ot open |
|000038b0| 66 6f 72 20 72 65 61 64 | 69 6e 67 2e 0a 58 0a 49 |for read|ing..X.I|
|000038c0| 66 20 66 64 74 74 79 20 | 68 61 73 20 77 72 69 74 |f fdtty |has writ|
|000038d0| 65 20 61 63 63 65 73 73 | 2c 20 61 6e 64 20 70 69 |e access|, and pi|
|000038e0| 64 20 69 73 20 74 68 65 | 20 63 75 72 72 65 6e 74 |d is the| current|
|000038f0| 20 70 72 6f 63 65 73 73 | 20 6f 72 20 61 20 63 68 | process| or a ch|
|00003900| 69 6c 64 20 6f 66 0a 74 | 68 65 20 63 75 72 72 65 |ild of.t|he curre|
|00003910| 6e 74 20 70 72 6f 63 65 | 73 73 2c 20 74 63 74 70 |nt proce|ss, tctp|
|00003920| 67 72 70 28 66 64 74 74 | 79 2c 70 69 64 29 20 73 |grp(fdtt|y,pid) s|
|00003930| 68 6f 75 6c 64 20 73 65 | 74 20 74 68 65 20 74 65 |hould se|t the te|
|00003940| 72 6d 69 6e 61 6c 27 73 | 0a 66 6f 72 65 67 72 6f |rminal's|.foregro|
|00003950| 75 6e 64 20 70 72 6f 63 | 65 73 73 20 67 72 6f 75 |und proc|ess grou|
|00003960| 70 20 74 6f 20 74 68 65 | 20 70 72 6f 63 65 73 73 |p to the| process|
|00003970| 20 67 72 6f 75 70 20 6f | 66 20 70 69 64 2e 20 54 | group o|f pid. T|
|00003980| 68 69 73 20 69 73 20 61 | 20 77 72 69 74 65 0a 6f |his is a| write.o|
|00003990| 70 65 72 61 74 69 6f 6e | 2e 20 59 6f 75 20 6d 61 |peration|. You ma|
|000039a0| 79 20 77 61 6e 74 20 74 | 6f 20 61 6c 6c 6f 77 20 |y want t|o allow |
|000039b0| 70 69 64 20 74 6f 20 62 | 65 20 61 6e 79 20 64 65 |pid to b|e any de|
|000039c0| 73 63 65 6e 64 61 6e 74 | 20 6f 66 20 74 68 65 20 |scendant| of the |
|000039d0| 63 75 72 72 65 6e 74 0a | 70 72 6f 63 65 73 73 20 |current.|process |
|000039e0| 28 75 6e 64 65 72 20 42 | 53 44 20 74 68 69 73 20 |(under B|SD this |
|000039f0| 73 69 6d 70 6c 69 66 69 | 65 73 20 74 68 65 20 69 |simplifi|es the i|
|00003a00| 6d 70 6c 65 6d 65 6e 74 | 61 74 69 6f 6e 29 2c 20 |mplement|ation), |
|00003a10| 62 75 74 20 74 68 69 73 | 20 69 73 20 6e 6f 74 0a |but this| is not.|
|00003a20| 6e 65 63 65 73 73 61 72 | 79 20 66 6f 72 20 61 20 |necessar|y for a |
|00003a30| 6a 6f 62 20 63 6f 6e 74 | 72 6f 6c 20 73 68 65 6c |job cont|rol shel|
|00003a40| 6c 2c 20 61 6e 64 20 6e | 6f 62 6f 64 79 20 69 73 |l, and n|obody is|
|00003a50| 20 67 6f 69 6e 67 20 74 | 6f 20 64 65 70 65 6e 64 | going t|o depend|
|00003a60| 20 6f 6e 20 74 68 61 74 | 0a 62 65 68 61 76 69 6f | on that|.behavio|
|00003a70| 72 2e 20 74 63 74 70 67 | 72 70 20 72 65 74 75 72 |r. tctpg|rp retur|
|00003a80| 6e 73 20 30 20 6f 6e 20 | 73 75 63 63 65 73 73 2c |ns 0 on |success,|
|00003a90| 20 2d 31 20 77 69 74 68 | 20 65 72 72 6e 6f 20 45 | -1 with| errno E|
|00003aa0| 4e 4f 54 54 59 20 69 66 | 20 66 64 74 74 79 20 69 |NOTTY if| fdtty i|
|00003ab0| 73 0a 6e 6f 74 20 61 20 | 74 65 72 6d 69 6e 61 6c |s.not a |terminal|
|00003ac0| 2c 20 2d 31 20 77 69 74 | 68 20 65 72 72 6e 6f 20 |, -1 wit|h errno |
|00003ad0| 45 53 52 43 48 20 69 66 | 20 70 69 64 20 64 6f 65 |ESRCH if| pid doe|
|00003ae0| 73 20 6e 6f 74 20 65 78 | 69 73 74 2c 20 2d 31 20 |s not ex|ist, -1 |
|00003af0| 77 69 74 68 20 65 72 72 | 6e 6f 0a 58 45 50 45 52 |with err|no.XEPER|
|00003b00| 4d 20 69 66 20 70 69 64 | 20 65 78 69 73 74 73 20 |M if pid| exists |
|00003b10| 62 75 74 20 69 73 20 6e | 6f 74 20 61 20 63 68 69 |but is n|ot a chi|
|00003b20| 6c 64 2f 64 65 73 63 65 | 6e 64 61 6e 74 2c 20 2d |ld/desce|ndant, -|
|00003b30| 31 20 77 69 74 68 20 65 | 72 72 6e 6f 20 45 42 41 |1 with e|rrno EBA|
|00003b40| 44 46 0a 69 66 20 66 64 | 74 74 79 20 69 73 20 6e |DF.if fd|tty is n|
|00003b50| 6f 74 20 6f 70 65 6e 20 | 66 6f 72 20 72 65 61 64 |ot open |for read|
|00003b60| 69 6e 67 2e 0a 58 0a 54 | 6f 20 69 6d 70 6c 65 6d |ing..X.T|o implem|
|00003b70| 65 6e 74 20 74 63 6e 65 | 77 70 67 72 70 28 29 20 |ent tcne|wpgrp() |
|00003b80| 79 6f 75 20 6e 65 65 64 | 20 74 6f 20 73 65 74 20 |you need| to set |
|00003b90| 75 70 20 61 20 74 61 62 | 6c 65 20 28 49 20 72 65 |up a tab|le (I re|
|00003ba0| 63 6f 6d 6d 65 6e 64 20 | 61 0a 63 68 61 69 6e 65 |commend |a.chaine|
|00003bb0| 64 20 68 61 73 68 20 74 | 61 62 6c 65 29 20 6f 66 |d hash t|able) of|
|00003bc0| 20 73 74 72 75 63 74 75 | 72 65 73 20 63 6f 6e 74 | structu|res cont|
|00003bd0| 61 69 6e 69 6e 67 20 70 | 72 6f 63 65 73 73 20 67 |aining p|rocess g|
|00003be0| 72 6f 75 70 20 6e 75 6d | 62 65 72 20 61 6e 64 0a |roup num|ber and.|
|00003bf0| 72 65 66 65 72 65 6e 63 | 65 20 63 6f 75 6e 74 2e |referenc|e count.|
|00003c00| 20 54 68 65 20 72 65 66 | 65 72 65 6e 63 65 20 63 | The ref|erence c|
|00003c10| 6f 75 6e 74 20 69 73 20 | 74 68 65 20 74 6f 74 61 |ount is |the tota|
|00003c20| 6c 20 6e 75 6d 62 65 72 | 20 6f 66 20 70 72 6f 63 |l number| of proc|
|00003c30| 65 73 73 65 73 0a 61 6e | 64 20 74 74 79 73 20 77 |esses.an|d ttys w|
|00003c40| 69 74 68 20 74 68 61 74 | 20 70 72 6f 63 65 73 73 |ith that| process|
|00003c50| 20 67 72 6f 75 70 2e 20 | 74 63 6e 65 77 70 67 72 | group. |tcnewpgr|
|00003c60| 70 28 29 20 63 61 6e 20 | 74 68 65 6e 20 73 65 61 |p() can |then sea|
|00003c70| 72 63 68 20 66 6f 72 20 | 61 0a 70 72 6f 63 65 73 |rch for |a.proces|
|00003c80| 73 20 67 72 6f 75 70 20 | 6e 6f 74 20 69 6e 20 74 |s group |not in t|
|00003c90| 68 65 20 74 61 62 6c 65 | 2e 20 54 68 65 20 72 61 |he table|. The ra|
|00003ca0| 6e 67 65 20 6f 66 20 70 | 72 6f 63 65 73 73 20 67 |nge of p|rocess g|
|00003cb0| 72 6f 75 70 20 6e 75 6d | 62 65 72 73 20 69 73 0a |roup num|bers is.|
|00003cc0| 6e 6f 74 20 69 6d 70 6f | 72 74 61 6e 74 3b 20 61 |not impo|rtant; a|
|00003cd0| 20 67 6f 6f 64 20 63 68 | 6f 69 63 65 20 66 6f 72 | good ch|oice for|
|00003ce0| 20 42 53 44 20 73 79 73 | 74 65 6d 73 20 69 73 20 | BSD sys|tems is |
|00003cf0| 33 32 38 30 31 2d 36 35 | 30 30 30 2e 20 48 6f 77 |32801-65|000. How|
|00003d00| 65 76 65 72 2c 20 69 74 | 0a 69 73 20 69 6d 70 6f |ever, it|.is impo|
|00003d10| 72 74 61 6e 74 20 74 68 | 61 74 20 74 68 65 72 65 |rtant th|at there|
|00003d20| 20 62 65 20 6d 6f 72 65 | 20 70 72 6f 63 65 73 73 | be more| process|
|00003d30| 20 67 72 6f 75 70 73 20 | 61 76 61 69 6c 61 62 6c | groups |availabl|
|00003d40| 65 20 74 68 61 6e 20 74 | 68 65 20 6d 61 78 69 6d |e than t|he maxim|
|00003d50| 75 6d 0a 70 6f 73 73 69 | 62 6c 65 20 6e 75 6d 62 |um.possi|ble numb|
|00003d60| 65 72 20 6f 66 20 74 74 | 79 73 20 61 6e 64 20 70 |er of tt|ys and p|
|00003d70| 69 64 73 20 69 6e 20 75 | 73 65 20 61 74 20 6f 6e |ids in u|se at on|
|00003d80| 63 65 2e 0a 58 0a 57 68 | 65 6e 65 76 65 72 20 61 |ce..X.Wh|enever a|
|00003d90| 20 70 72 6f 63 65 73 73 | 20 69 73 20 63 72 65 61 | process| is crea|
|00003da0| 74 65 64 2c 20 74 68 65 | 20 72 65 66 65 72 65 6e |ted, the| referen|
|00003db0| 63 65 20 63 6f 75 6e 74 | 20 66 6f 72 20 69 74 73 |ce count| for its|
|00003dc0| 20 70 72 6f 63 65 73 73 | 20 67 72 6f 75 70 0a 58 | process| group.X|
|00003dd0| 28 69 66 20 74 68 61 74 | 20 67 72 6f 75 70 20 69 |(if that| group i|
|00003de0| 73 20 6e 6f 74 20 30 29 | 20 6d 75 73 74 20 62 65 |s not 0)| must be|
|00003df0| 20 69 6e 63 72 65 6d 65 | 6e 74 65 64 3b 20 77 68 | increme|nted; wh|
|00003e00| 65 6e 65 76 65 72 20 61 | 20 70 72 6f 63 65 73 73 |enever a| process|
|00003e10| 20 64 69 65 73 2c 0a 74 | 68 65 20 72 65 66 65 72 | dies,.t|he refer|
|00003e20| 65 6e 63 65 20 63 6f 75 | 6e 74 20 66 6f 72 20 69 |ence cou|nt for i|
|00003e30| 74 73 20 70 72 6f 63 65 | 73 73 20 67 72 6f 75 70 |ts proce|ss group|
|00003e40| 20 28 69 66 20 74 68 61 | 74 20 67 72 6f 75 70 20 | (if tha|t group |
|00003e50| 69 73 20 6e 6f 74 20 30 | 29 20 6d 75 73 74 0a 62 |is not 0|) must.b|
|00003e60| 65 20 64 65 63 72 65 6d | 65 6e 74 65 64 3b 20 77 |e decrem|ented; w|
|00003e70| 68 65 6e 65 76 65 72 20 | 61 20 70 72 6f 63 65 73 |henever |a proces|
|00003e80| 73 20 63 68 61 6e 67 65 | 73 20 70 72 6f 63 65 73 |s change|s proces|
|00003e90| 73 20 67 72 6f 75 70 73 | 20 28 65 2e 67 2e 2c 20 |s groups| (e.g., |
|00003ea0| 76 69 61 0a 73 65 74 74 | 70 67 72 70 28 29 29 2c |via.sett|pgrp()),|
|00003eb0| 20 74 68 65 20 72 65 66 | 65 72 65 6e 63 65 20 63 | the ref|erence c|
|00003ec0| 6f 75 6e 74 73 20 66 6f | 72 20 6f 6c 64 20 61 6e |ounts fo|r old an|
|00003ed0| 64 20 6e 65 77 20 67 72 | 6f 75 70 73 20 6d 75 73 |d new gr|oups mus|
|00003ee0| 74 20 62 65 20 73 65 74 | 0a 61 70 70 72 6f 70 72 |t be set|.appropr|
|00003ef0| 69 61 74 65 6c 79 3b 20 | 61 6e 64 20 77 68 65 6e |iately; |and when|
|00003f00| 65 76 65 72 20 61 20 74 | 74 79 20 63 68 61 6e 67 |ever a t|ty chang|
|00003f10| 65 73 20 70 72 6f 63 65 | 73 73 20 67 72 6f 75 70 |es proce|ss group|
|00003f20| 73 20 28 65 2e 67 2e 2c | 20 76 69 61 0a 74 63 6e |s (e.g.,| via.tcn|
|00003f30| 65 77 70 67 72 70 28 29 | 20 6f 72 20 74 63 74 70 |ewpgrp()| or tctp|
|00003f40| 67 72 70 28 29 29 2c 20 | 74 68 65 20 72 65 66 65 |grp()), |the refe|
|00003f50| 72 65 6e 63 65 20 63 6f | 75 6e 74 73 20 6d 75 73 |rence co|unts mus|
|00003f60| 74 20 61 6c 73 6f 20 62 | 65 20 73 65 74 0a 61 70 |t also b|e set.ap|
|00003f70| 70 72 6f 70 72 69 61 74 | 65 6c 79 2e 20 54 68 61 |propriat|ely. Tha|
|00003f80| 74 27 73 20 69 74 2e 0a | 58 0a 41 20 64 69 66 66 |t's it..|X.A diff|
|00003f90| 65 72 65 6e 74 20 69 6d | 70 6c 65 6d 65 6e 74 61 |erent im|plementa|
|00003fa0| 74 69 6f 6e 20 73 74 72 | 61 74 65 67 79 20 68 61 |tion str|ategy ha|
|00003fb0| 73 20 62 65 65 6e 20 73 | 75 67 67 65 73 74 65 64 |s been s|uggested|
|00003fc0| 20 62 79 20 4a 6f 68 6e | 20 43 61 72 72 3a 20 74 | by John| Carr: t|
|00003fd0| 68 65 0a 73 79 73 74 65 | 6d 20 63 61 6e 20 73 69 |he.syste|m can si|
|00003fe0| 6d 70 6c 79 20 61 73 73 | 69 67 6e 20 67 72 6f 75 |mply ass|ign grou|
|00003ff0| 70 20 6e 75 6d 62 65 72 | 73 20 69 6e 20 69 6e 63 |p number|s in inc|
|00004000| 72 65 61 73 69 6e 67 20 | 6f 72 64 65 72 20 73 74 |reasing |order st|
|00004010| 61 72 74 69 6e 67 20 66 | 72 6f 6d 0a 62 6f 6f 74 |arting f|rom.boot|
|00004020| 20 74 69 6d 65 2e 20 49 | 66 2c 20 66 6f 72 20 69 | time. I|f, for i|
|00004030| 6e 73 74 61 6e 63 65 2c | 20 61 20 70 72 6f 63 65 |nstance,| a proce|
|00004040| 73 73 20 67 72 6f 75 70 | 20 68 61 73 20 36 34 20 |ss group| has 64 |
|00004050| 62 69 74 73 2c 20 61 6e | 64 20 74 68 65 72 65 20 |bits, an|d there |
|00004060| 61 72 65 0a 61 74 20 6d | 6f 73 74 20 61 20 62 69 |are.at m|ost a bi|
|00004070| 6c 6c 69 6f 6e 20 70 72 | 6f 63 65 73 73 20 67 72 |llion pr|ocess gr|
|00004080| 6f 75 70 20 6d 61 6e 69 | 70 75 6c 61 74 69 6f 6e |oup mani|pulation|
|00004090| 73 20 70 65 72 20 73 65 | 63 6f 6e 64 2c 20 69 74 |s per se|cond, it|
|000040a0| 20 77 69 6c 6c 20 62 65 | 0a 6d 6f 72 65 20 74 68 | will be|.more th|
|000040b0| 61 6e 20 35 38 34 20 79 | 65 61 72 73 20 62 65 66 |an 584 y|ears bef|
|000040c0| 6f 72 65 20 74 68 65 20 | 6e 75 6d 62 65 72 73 20 |ore the |numbers |
|000040d0| 63 61 6e 20 72 65 70 65 | 61 74 2e 20 4e 61 74 75 |can repe|at. Natu|
|000040e0| 72 61 6c 6c 79 2c 20 73 | 79 73 74 65 6d 0a 61 64 |rally, s|ystem.ad|
|000040f0| 6d 69 6e 69 73 74 72 61 | 74 6f 72 73 20 73 68 6f |ministra|tors sho|
|00004100| 75 6c 64 20 6b 65 65 70 | 20 61 20 63 6c 6f 73 65 |uld keep| a close|
|00004110| 20 65 79 65 20 6f 6e 20 | 72 65 63 65 6e 74 6c 79 | eye on |recently|
|00004120| 20 61 6c 6c 6f 63 61 74 | 65 64 20 70 72 6f 63 65 | allocat|ed proce|
|00004130| 73 73 0a 67 72 6f 75 70 | 73 2c 20 61 6e 64 20 62 |ss.group|s, and b|
|00004140| 65 20 70 72 65 70 61 72 | 65 64 20 74 6f 20 62 72 |e prepar|ed to br|
|00004150| 69 6e 67 20 74 68 65 20 | 73 79 73 74 65 6d 20 64 |ing the |system d|
|00004160| 6f 77 6e 20 66 6f 72 20 | 6d 61 69 6e 74 65 6e 61 |own for |maintena|
|00004170| 6e 63 65 20 61 73 20 73 | 6f 6f 6e 0a 61 73 20 74 |nce as s|oon.as t|
|00004180| 68 65 72 65 20 69 73 20 | 61 6e 79 20 72 69 73 6b |here is |any risk|
|00004190| 20 6f 66 20 72 65 70 65 | 74 69 74 69 6f 6e 2e 0a | of repe|tition..|
|000041a0| 58 0a 54 68 65 73 65 20 | 74 68 72 65 65 20 70 72 |X.These |three pr|
|000041b0| 6f 63 65 73 73 20 67 72 | 6f 75 70 20 6d 61 6e 69 |ocess gr|oup mani|
|000041c0| 70 75 6c 61 74 69 6f 6e | 20 63 61 6c 6c 73 20 64 |pulation| calls d|
|000041d0| 6f 20 6e 6f 74 20 61 6c | 6c 6f 77 20 61 6e 79 20 |o not al|low any |
|000041e0| 61 62 75 73 65 2e 20 54 | 6f 0a 73 65 74 20 61 20 |abuse. T|o.set a |
|000041f0| 74 65 72 6d 69 6e 61 6c | 20 74 6f 20 73 6f 6d 65 |terminal| to some|
|00004200| 6f 6e 65 20 65 6c 73 65 | 27 73 20 28 6e 6f 6e 7a |one else|'s (nonz|
|00004210| 65 72 6f 29 20 70 72 6f | 63 65 73 73 20 67 72 6f |ero) pro|cess gro|
|00004220| 75 70 20 77 69 74 68 20 | 74 63 74 70 67 72 70 28 |up with |tctpgrp(|
|00004230| 29 2c 0a 61 6e 20 61 74 | 74 61 63 6b 65 72 20 77 |),.an at|tacker w|
|00004240| 6f 75 6c 64 20 6e 65 65 | 64 20 61 20 63 68 69 6c |ould nee|d a chil|
|00004250| 64 20 70 72 6f 63 65 73 | 73 20 61 6c 72 65 61 64 |d proces|s alread|
|00004260| 79 20 69 6e 20 74 68 65 | 20 67 72 6f 75 70 2e 20 |y in the| group. |
|00004270| 42 75 74 20 74 6f 20 70 | 75 74 0a 61 20 70 72 6f |But to p|ut.a pro|
|00004280| 63 65 73 73 20 69 6e 74 | 6f 20 73 6f 6d 65 6f 6e |cess int|o someon|
|00004290| 65 20 65 6c 73 65 27 73 | 20 28 6e 6f 6e 7a 65 72 |e else's| (nonzer|
|000042a0| 6f 29 20 70 72 6f 63 65 | 73 73 20 67 72 6f 75 70 |o) proce|ss group|
|000042b0| 20 77 69 74 68 20 73 65 | 74 74 70 67 72 70 28 29 | with se|ttpgrp()|
|000042c0| 2c 0a 61 6e 20 61 74 74 | 61 63 6b 65 72 20 77 6f |,.an att|acker wo|
|000042d0| 75 6c 64 20 61 6c 72 65 | 61 64 79 20 6e 65 65 64 |uld alre|ady need|
|000042e0| 20 61 63 63 65 73 73 20 | 74 6f 20 61 20 74 74 79 | access |to a tty|
|000042f0| 20 77 69 74 68 20 74 68 | 61 74 20 67 72 6f 75 70 | with th|at group|
|00004300| 21 20 54 68 65 72 65 27 | 73 0a 6e 6f 20 77 61 79 |! There'|s.no way|
|00004310| 20 74 6f 20 62 72 65 61 | 6b 20 69 6e 74 6f 20 74 | to brea|k into t|
|00004320| 68 69 73 20 63 69 72 63 | 6c 65 2e 20 74 63 6e 65 |his circ|le. tcne|
|00004330| 77 70 67 72 70 28 29 20 | 69 73 20 75 73 65 6c 65 |wpgrp() |is usele|
|00004340| 73 73 20 66 6f 72 20 61 | 74 74 61 63 6b 73 0a 73 |ss for a|ttacks.s|
|00004350| 69 6e 63 65 20 69 74 20 | 64 6f 65 73 20 6e 6f 74 |ince it |does not|
|00004360| 20 6c 65 74 20 61 6e 20 | 61 74 74 61 63 6b 65 72 | let an |attacker|
|00004370| 20 6a 6f 69 6e 20 61 6e | 20 65 78 69 73 74 69 6e | join an| existin|
|00004380| 67 20 67 72 6f 75 70 2e | 20 48 65 6e 63 65 20 74 |g group.| Hence t|
|00004390| 68 65 0a 73 79 73 74 65 | 6d 20 69 73 20 73 65 63 |he.syste|m is sec|
|000043a0| 75 72 65 2e 20 54 6f 67 | 65 74 68 65 72 20 77 69 |ure. Tog|ether wi|
|000043b0| 74 68 20 74 68 65 20 62 | 61 73 69 63 20 6a 6f 62 |th the b|asic job|
|000043c0| 20 63 6f 6e 74 72 6f 6c | 20 66 65 61 74 75 72 65 | control| feature|
|000043d0| 73 20 6f 75 74 6c 69 6e | 65 64 0a 69 6e 20 73 65 |s outlin|ed.in se|
|000043e0| 63 74 69 6f 6e 73 20 32 | 20 74 68 72 6f 75 67 68 |ctions 2| through|
|000043f0| 20 36 2c 20 74 68 69 73 | 20 70 72 6f 76 69 64 65 | 6, this| provide|
|00004400| 73 20 61 20 63 6f 6d 70 | 6c 65 74 65 2c 20 75 73 |s a comp|lete, us|
|00004410| 61 62 6c 65 20 6a 6f 62 | 20 63 6f 6e 74 72 6f 6c |able job| control|
|00004420| 0a 73 79 73 74 65 6d 2e | 0a 58 0a 58 46 6f 72 20 |.system.|.X.XFor |
|00004430| 63 6f 6d 70 61 72 69 73 | 6f 6e 2c 20 42 53 44 20 |comparis|on, BSD |
|00004440| 6a 6f 62 20 63 6f 6e 74 | 72 6f 6c 20 69 6e 76 6f |job cont|rol invo|
|00004450| 6c 76 65 73 20 63 6f 6e | 74 72 6f 6c 6c 69 6e 67 |lves con|trolling|
|00004460| 20 74 74 79 73 2c 20 61 | 6e 64 20 68 61 73 20 73 | ttys, a|nd has s|
|00004470| 69 78 0a 69 6e 74 65 72 | 66 61 63 65 20 66 75 6e |ix.inter|face fun|
|00004480| 63 74 69 6f 6e 73 20 62 | 65 79 6f 6e 64 20 74 68 |ctions b|eyond th|
|00004490| 65 20 6d 65 63 68 61 6e | 69 73 6d 73 20 6d 65 6e |e mechan|isms men|
|000044a0| 74 69 6f 6e 65 64 20 69 | 6e 20 73 65 63 74 69 6f |tioned i|n sectio|
|000044b0| 6e 73 20 32 0a 74 68 72 | 6f 75 67 68 20 36 3a 20 |ns 2.thr|ough 6: |
|000044c0| 6f 70 65 6e 28 29 20 28 | 6f 66 20 61 20 74 74 79 |open() (|of a tty|
|000044d0| 29 2c 20 73 65 74 70 67 | 72 70 28 29 2c 20 67 65 |), setpg|rp(), ge|
|000044e0| 74 70 67 72 70 28 29 2c | 20 74 68 65 20 54 49 4f |tpgrp(),| the TIO|
|000044f0| 43 47 50 47 52 50 20 69 | 6f 63 74 6c 2c 0a 74 68 |CGPGRP i|octl,.th|
|00004500| 65 20 54 49 4f 43 53 50 | 47 52 50 20 69 6f 63 74 |e TIOCSP|GRP ioct|
|00004510| 6c 2c 20 61 6e 64 20 74 | 68 65 20 54 49 4f 43 4e |l, and t|he TIOCN|
|00004520| 4f 54 54 59 20 69 6f 63 | 74 6c 2e 20 43 6f 6e 74 |OTTY ioc|tl. Cont|
|00004530| 72 6f 6c 6c 69 6e 67 20 | 74 65 72 6d 69 6e 61 6c |rolling |terminal|
|00004540| 73 0a 61 66 66 65 63 74 | 20 74 68 65 20 65 6e 74 |s.affect| the ent|
|00004550| 69 72 65 20 6a 6f 62 20 | 63 6f 6e 74 72 6f 6c 20 |ire job |control |
|00004560| 73 79 73 74 65 6d 20 61 | 6e 64 20 6d 61 6b 65 20 |system a|nd make |
|00004570| 65 76 65 72 79 74 68 69 | 6e 67 20 68 61 72 64 65 |everythi|ng harde|
|00004580| 72 20 74 6f 0a 70 72 6f | 67 72 61 6d 20 61 6e 64 |r to.pro|gram and|
|00004590| 20 75 73 65 2e 0a 58 0a | 50 4f 53 49 58 20 6a 6f | use..X.|POSIX jo|
|000045a0| 62 20 63 6f 6e 74 72 6f | 6c 20 69 73 20 65 76 65 |b contro|l is eve|
|000045b0| 6e 20 77 6f 72 73 65 3a | 20 69 74 20 69 6e 63 6c |n worse:| it incl|
|000045c0| 75 64 65 73 20 6e 6f 74 | 20 6f 6e 6c 79 20 74 68 |udes not| only th|
|000045d0| 65 20 65 6e 74 69 72 65 | 0a 63 6f 6d 70 6c 65 78 |e entire|.complex|
|000045e0| 69 74 79 20 6f 66 20 74 | 68 65 20 42 53 44 20 69 |ity of t|he BSD i|
|000045f0| 6e 74 65 72 66 61 63 65 | 2c 20 62 75 74 20 69 74 |nterface|, but it|
|00004600| 20 68 61 73 20 60 60 73 | 65 73 73 69 6f 6e 73 27 | has ``s|essions'|
|00004610| 27 20 77 69 74 68 20 65 | 66 66 65 63 74 73 0a 65 |' with e|ffects.e|
|00004620| 76 65 6e 20 6d 6f 72 65 | 20 70 65 72 76 61 73 69 |ven more| pervasi|
|00004630| 76 65 20 74 68 61 6e 20 | 74 68 6f 73 65 20 6f 66 |ve than |those of|
|00004640| 20 63 6f 6e 74 72 6f 6c | 6c 69 6e 67 20 74 65 72 | control|ling ter|
|00004650| 6d 69 6e 61 6c 73 2e 20 | 28 46 6f 72 20 69 6e 73 |minals. |(For ins|
|00004660| 74 61 6e 63 65 2c 0a 61 | 20 70 72 6f 63 65 73 73 |tance,.a| process|
|00004670| 20 63 61 6e 20 6f 6e 6c | 79 20 62 65 20 73 74 6f | can onl|y be sto|
|00004680| 70 70 65 64 20 69 66 20 | 69 74 73 20 70 61 72 65 |pped if |its pare|
|00004690| 6e 74 20 69 73 20 69 6e | 20 74 68 65 20 2a 73 61 |nt is in| the *sa|
|000046a0| 6d 65 2a 20 73 65 73 73 | 69 6f 6e 20 62 75 74 0a |me* sess|ion but.|
|000046b0| 61 20 2a 64 69 66 66 65 | 72 65 6e 74 2a 20 70 72 |a *diffe|rent* pr|
|000046c0| 6f 63 65 73 73 20 67 72 | 6f 75 70 2e 29 0a 58 0a |ocess gr|oup.).X.|
|000046d0| 58 0a 58 38 2e 20 49 6d | 70 6c 65 6d 65 6e 74 69 |X.X8. Im|plementi|
|000046e0| 6e 67 20 74 68 65 20 6e | 65 77 20 6a 6f 62 20 63 |ng the n|ew job c|
|000046f0| 6f 6e 74 72 6f 6c 20 69 | 6e 74 65 72 66 61 63 65 |ontrol i|nterface|
|00004700| 20 69 6e 20 61 20 42 53 | 44 20 73 79 73 74 65 6d | in a BS|D system|
|00004710| 0a 58 0a 74 63 6e 65 77 | 70 67 72 70 28 29 20 72 |.X.tcnew|pgrp() r|
|00004720| 65 71 75 69 72 65 73 20 | 6b 65 72 6e 65 6c 20 63 |equires |kernel c|
|00004730| 68 61 6e 67 65 73 20 6f | 6e 20 61 6e 79 20 73 79 |hanges o|n any sy|
|00004740| 73 74 65 6d 3b 20 63 75 | 72 72 65 6e 74 20 73 79 |stem; cu|rrent sy|
|00004750| 73 74 65 6d 73 20 64 6f | 0a 6e 6f 74 20 72 65 63 |stems do|.not rec|
|00004760| 6f 67 6e 69 7a 65 20 61 | 20 72 61 6e 67 65 20 6f |ognize a| range o|
|00004770| 66 20 70 72 6f 63 65 73 | 73 20 67 72 6f 75 70 73 |f proces|s groups|
|00004780| 20 74 6f 20 62 65 20 64 | 79 6e 61 6d 69 63 61 6c | to be d|ynamical|
|00004790| 6c 79 20 61 6c 6c 6f 63 | 61 74 65 64 20 74 6f 0a |ly alloc|ated to.|
|000047a0| 74 74 79 73 2e 20 49 74 | 20 61 6c 73 6f 20 61 6c |ttys. It| also al|
|000047b0| 6c 6f 77 73 20 61 20 73 | 74 79 6c 65 20 6f 66 20 |lows a s|tyle of |
|000047c0| 6a 6f 62 2d 63 6f 6e 74 | 72 6f 6c 20 70 72 6f 67 |job-cont|rol prog|
|000047d0| 72 61 6d 6d 69 6e 67 20 | 73 6f 6d 65 77 68 61 74 |ramming |somewhat|
|000047e0| 0a 64 69 66 66 65 72 65 | 6e 74 20 66 72 6f 6d 20 |.differe|nt from |
|000047f0| 74 68 65 20 75 73 75 61 | 6c 20 42 53 44 20 73 74 |the usua|l BSD st|
|00004800| 79 6c 65 2e 20 48 6f 77 | 65 76 65 72 2c 20 73 65 |yle. How|ever, se|
|00004810| 74 74 70 67 72 70 28 29 | 20 61 6e 64 20 74 63 74 |ttpgrp()| and tct|
|00004820| 70 67 72 70 28 29 0a 63 | 61 6e 20 62 65 20 69 6d |pgrp().c|an be im|
|00004830| 70 6c 65 6d 65 6e 74 65 | 64 20 61 73 20 6c 69 62 |plemente|d as lib|
|00004840| 72 61 72 79 20 72 6f 75 | 74 69 6e 65 73 20 75 6e |rary rou|tines un|
|00004850| 64 65 72 20 42 53 44 2e | 20 48 65 72 65 20 74 68 |der BSD.| Here th|
|00004860| 65 79 20 61 72 65 3a 0a | 58 0a 58 20 20 20 69 6e |ey are:.|X.X in|
|00004870| 74 20 73 65 74 74 70 67 | 72 70 28 66 64 74 74 79 |t settpg|rp(fdtty|
|00004880| 29 0a 58 20 20 20 69 6e | 74 20 66 64 74 74 79 3b |).X in|t fdtty;|
|00004890| 0a 58 20 20 20 7b 0a 58 | 20 20 20 20 69 6e 74 20 |.X {.X| int |
|000048a0| 70 67 72 70 20 3d 20 30 | 3b 0a 58 20 20 20 20 69 |pgrp = 0|;.X i|
|000048b0| 66 20 28 66 64 74 74 79 | 20 21 3d 20 2d 31 29 0a |f (fdtty| != -1).|
|000048c0| 58 20 20 20 20 20 20 69 | 66 20 28 69 6f 63 74 6c |X i|f (ioctl|
|000048d0| 28 66 64 74 74 79 2c 54 | 49 4f 43 47 50 47 52 50 |(fdtty,T|IOCGPGRP|
|000048e0| 2c 26 70 67 72 70 29 20 | 3d 3d 20 2d 31 29 0a 58 |,&pgrp) |== -1).X|
|000048f0| 20 20 20 20 20 20 20 20 | 72 65 74 75 72 6e 20 2d | |return -|
|00004900| 31 3b 0a 58 20 20 20 20 | 72 65 74 75 72 6e 20 73 |1;.X |return s|
|00004910| 65 74 70 67 72 70 28 30 | 2c 70 67 72 70 29 3b 0a |etpgrp(0|,pgrp);.|
|00004920| 58 20 20 20 7d 0a 58 0a | 58 20 20 20 69 6e 74 20 |X }.X.|X int |
|00004930| 74 63 74 70 67 72 70 28 | 66 64 74 74 79 2c 70 69 |tctpgrp(|fdtty,pi|
|00004940| 64 29 0a 58 20 20 20 69 | 6e 74 20 66 64 74 74 79 |d).X i|nt fdtty|
|00004950| 3b 0a 58 20 20 20 69 6e | 74 20 70 69 64 3b 0a 58 |;.X in|t pid;.X|
|00004960| 20 20 20 7b 0a 58 20 20 | 20 20 69 6e 74 20 70 67 | {.X | int pg|
|00004970| 72 70 3b 0a 58 20 20 20 | 20 69 66 20 28 28 70 67 |rp;.X | if ((pg|
|00004980| 72 70 20 3d 20 67 65 74 | 70 67 72 70 28 70 69 64 |rp = get|pgrp(pid|
|00004990| 29 29 20 3d 3d 20 2d 31 | 29 0a 58 20 20 20 20 20 |)) == -1|).X |
|000049a0| 20 72 65 74 75 72 6e 20 | 2d 31 3b 0a 58 20 20 20 | return |-1;.X |
|000049b0| 20 72 65 74 75 72 6e 20 | 69 6f 63 74 6c 28 66 64 | return |ioctl(fd|
|000049c0| 74 74 79 2c 54 49 4f 43 | 53 50 47 52 50 2c 26 70 |tty,TIOC|SPGRP,&p|
|000049d0| 67 72 70 29 3b 0a 58 20 | 20 20 7d 0a 58 0a 4e 6f |grp);.X | }.X.No|
|000049e0| 74 65 20 74 68 61 74 20 | 74 68 69 73 20 69 6e 74 |te that |this int|
|000049f0| 65 72 66 61 63 65 20 64 | 6f 65 73 6e 27 74 20 69 |erface d|oesn't i|
|00004a00| 6e 74 65 72 61 63 74 20 | 77 69 74 68 20 63 6f 6e |nteract |with con|
|00004a10| 74 72 6f 6c 6c 69 6e 67 | 20 74 74 79 73 20 69 6e |trolling| ttys in|
|00004a20| 20 61 6e 79 0a 77 61 79 | 2e 20 55 6e 66 6f 72 74 | any.way|. Unfort|
|00004a30| 75 6e 61 74 65 6c 79 2c | 20 63 6f 6e 74 72 6f 6c |unately,| control|
|00004a40| 6c 69 6e 67 20 74 74 79 | 73 20 73 6f 6d 65 74 69 |ling tty|s someti|
|00004a50| 6d 65 73 20 66 6f 72 63 | 65 20 74 68 65 69 72 20 |mes forc|e their |
|00004a60| 6f 77 6e 0a 69 6e 74 65 | 72 61 63 74 69 6f 6e 73 |own.inte|ractions|
|00004a70| 2c 20 61 6e 64 20 61 20 | 6a 6f 62 20 63 6f 6e 74 |, and a |job cont|
|00004a80| 72 6f 6c 20 61 70 70 6c | 69 63 61 74 69 6f 6e 20 |rol appl|ication |
|00004a90| 77 68 69 63 68 20 6d 61 | 6e 69 70 75 6c 61 74 65 |which ma|nipulate|
|00004aa0| 73 20 74 74 79 73 20 28 | 61 73 0a 6f 70 70 6f 73 |s ttys (|as.oppos|
|00004ab0| 65 64 20 74 6f 20 61 20 | 73 68 65 6c 6c 2c 20 77 |ed to a |shell, w|
|00004ac0| 68 69 63 68 20 6d 65 72 | 65 6c 79 20 72 75 6e 73 |hich mer|ely runs|
|00004ad0| 20 75 6e 64 65 72 20 61 | 20 73 69 6e 67 6c 65 20 | under a| single |
|00004ae0| 74 74 79 29 20 73 68 6f | 75 6c 64 20 73 74 69 6c |tty) sho|uld stil|
|00004af0| 6c 0a 62 65 20 61 77 61 | 72 65 20 6f 66 20 74 68 |l.be awa|re of th|
|00004b00| 65 20 6f 6c 64 20 63 6f | 6e 74 72 6f 6c 6c 69 6e |e old co|ntrollin|
|00004b10| 67 20 74 74 79 20 72 75 | 6c 65 73 2e 20 54 68 65 |g tty ru|les. The|
|00004b20| 20 73 61 6d 65 20 69 73 | 20 74 72 75 65 20 69 6e | same is| true in|
|00004b30| 20 66 61 72 0a 67 72 65 | 61 74 65 72 20 6d 65 61 | far.gre|ater mea|
|00004b40| 73 75 72 65 20 75 6e 64 | 65 72 20 50 4f 53 49 58 |sure und|er POSIX|
|00004b50| 2d 2d 2d 79 6f 75 20 73 | 69 6d 70 6c 79 20 63 61 |---you s|imply ca|
|00004b60| 6e 6e 6f 74 20 69 67 6e | 6f 72 65 20 73 65 73 73 |nnot ign|ore sess|
|00004b70| 69 6f 6e 73 2c 20 62 65 | 63 61 75 73 65 0a 79 6f |ions, be|cause.yo|
|00004b80| 75 20 77 69 6c 6c 20 6f | 70 65 6e 20 75 70 20 72 |u will o|pen up r|
|00004b90| 61 74 68 65 72 20 6c 61 | 72 67 65 20 73 65 63 75 |ather la|rge secu|
|00004ba0| 72 69 74 79 20 68 6f 6c | 65 73 20 69 66 20 79 6f |rity hol|es if yo|
|00004bb0| 75 20 6c 65 61 76 65 20 | 61 6c 6c 20 70 72 6f 63 |u leave |all proc|
|00004bc0| 65 73 73 65 73 0a 69 6e | 20 74 68 65 20 73 61 6d |esses.in| the sam|
|00004bd0| 65 20 73 65 73 73 69 6f | 6e 2e 20 50 75 74 20 73 |e sessio|n. Put s|
|00004be0| 69 6d 70 6c 79 2c 20 74 | 68 65 20 50 4f 53 49 58 |imply, t|he POSIX|
|00004bf0| 20 73 74 61 6e 64 61 72 | 64 20 66 6f 72 63 65 73 | standar|d forces|
|00004c00| 20 73 79 73 74 65 6d 20 | 63 6f 64 65 0a 74 6f 20 | system |code.to |
|00004c10| 6d 61 6e 69 70 75 6c 61 | 74 65 20 73 65 73 73 69 |manipula|te sessi|
|00004c20| 6f 6e 73 20 66 6f 72 20 | 69 74 73 20 68 65 61 6c |ons for |its heal|
|00004c30| 74 68 2e 0a 58 0a 58 0a | 58 39 2e 20 50 72 6f 67 |th..X.X.|X9. Prog|
|00004c40| 72 61 6d 6d 69 6e 67 20 | 63 6f 6d 6d 6f 6e 20 6f |ramming |common o|
|00004c50| 70 65 72 61 74 69 6f 6e | 73 20 77 69 74 68 20 74 |peration|s with t|
|00004c60| 68 65 20 6e 65 77 20 6a | 6f 62 20 63 6f 6e 74 72 |he new j|ob contr|
|00004c70| 6f 6c 20 69 6e 74 65 72 | 66 61 63 65 0a 58 0a 58 |ol inter|face.X.X|
|00004c80| 46 6f 72 6b 69 6e 67 20 | 61 20 70 69 70 65 6c 69 |Forking |a pipeli|
|00004c90| 6e 65 20 69 6e 20 61 20 | 6a 6f 62 2d 63 6f 6e 74 |ne in a |job-cont|
|00004ca0| 72 6f 6c 20 73 68 65 6c | 6c 3a 20 54 68 65 20 73 |rol shel|l: The s|
|00004cb0| 68 65 6c 6c 20 73 74 61 | 72 74 73 20 77 69 74 68 |hell sta|rts with|
|00004cc0| 0a 74 63 6e 65 77 70 67 | 72 70 28 66 64 74 74 79 |.tcnewpg|rp(fdtty|
|00004cd0| 29 2c 20 73 6f 20 74 68 | 61 74 20 74 68 65 20 74 |), so th|at the t|
|00004ce0| 74 79 20 69 73 20 69 6e | 20 74 68 65 20 6e 65 77 |ty is in| the new|
|00004cf0| 20 70 72 6f 63 65 73 73 | 20 67 72 6f 75 70 20 62 | process| group b|
|00004d00| 65 66 6f 72 65 0a 74 68 | 65 72 65 20 61 72 65 20 |efore.th|ere are |
|00004d10| 65 76 65 6e 20 61 6e 79 | 20 63 68 69 6c 64 72 65 |even any| childre|
|00004d20| 6e 2e 20 28 54 68 61 74 | 27 73 20 74 68 65 20 62 |n. (That|'s the b|
|00004d30| 61 73 69 63 20 64 69 66 | 66 65 72 65 6e 63 65 20 |asic dif|ference |
|00004d40| 62 65 74 77 65 65 6e 20 | 74 68 65 0a 42 53 44 20 |between |the.BSD |
|00004d50| 61 6e 64 20 50 4f 53 49 | 58 20 6d 6f 64 65 6c 73 |and POSI|X models|
|00004d60| 20 61 6e 64 20 74 68 69 | 73 20 6f 6e 65 2e 29 20 | and thi|s one.) |
|00004d70| 49 74 20 74 68 65 6e 20 | 66 6f 72 6b 73 20 65 61 |It then |forks ea|
|00004d80| 63 68 20 70 72 6f 63 65 | 73 73 20 69 6e 20 74 68 |ch proce|ss in th|
|00004d90| 65 0a 70 69 70 65 6c 69 | 6e 65 2e 20 45 61 63 68 |e.pipeli|ne. Each|
|00004da0| 20 70 72 6f 63 65 73 73 | 20 64 6f 65 73 20 73 65 | process| does se|
|00004db0| 74 74 70 67 72 70 28 66 | 64 74 74 79 29 2c 20 74 |ttpgrp(f|dtty), t|
|00004dc0| 68 75 73 20 6a 6f 69 6e | 69 6e 67 20 74 68 65 20 |hus join|ing the |
|00004dd0| 6e 65 77 0a 70 72 6f 63 | 65 73 73 20 67 72 6f 75 |new.proc|ess grou|
|00004de0| 70 2c 20 62 65 66 6f 72 | 65 20 69 74 20 65 78 65 |p, befor|e it exe|
|00004df0| 63 28 29 73 20 74 68 65 | 20 61 70 70 72 6f 70 72 |c()s the| appropr|
|00004e00| 69 61 74 65 20 70 72 6f | 67 72 61 6d 2e 20 4e 6f |iate pro|gram. No|
|00004e10| 74 65 20 74 68 61 74 20 | 74 6f 0a 61 76 6f 69 64 |te that |to.avoid|
|00004e20| 20 72 61 63 65 73 20 74 | 68 65 20 73 68 65 6c 6c | races t|he shell|
|00004e30| 20 73 68 6f 75 6c 64 20 | 62 6c 6f 63 6b 20 53 49 | should |block SI|
|00004e40| 47 43 48 4c 44 20 77 68 | 69 6c 65 20 69 74 27 73 |GCHLD wh|ile it's|
|00004e50| 20 73 70 61 77 6e 69 6e | 67 20 63 68 69 6c 64 72 | spawnin|g childr|
|00004e60| 65 6e 2e 0a 58 0a 48 61 | 6e 64 6c 69 6e 67 20 61 |en..X.Ha|ndling a|
|00004e70| 20 73 74 6f 70 70 65 64 | 20 63 68 69 6c 64 20 70 | stopped| child p|
|00004e80| 72 6f 63 65 73 73 3a 20 | 57 68 65 6e 20 74 68 65 |rocess: |When the|
|00004e90| 20 73 68 65 6c 6c 20 73 | 65 65 73 20 74 68 61 74 | shell s|ees that|
|00004ea0| 20 61 20 70 69 70 65 6c | 69 6e 65 0a 68 61 73 20 | a pipel|ine.has |
|00004eb0| 73 74 6f 70 70 65 64 20 | 6f 72 20 65 78 69 74 65 |stopped |or exite|
|00004ec0| 64 2c 20 69 74 20 64 6f | 65 73 20 74 63 74 70 67 |d, it do|es tctpg|
|00004ed0| 72 70 28 66 64 74 74 79 | 2c 67 65 74 70 69 64 28 |rp(fdtty|,getpid(|
|00004ee0| 29 29 20 74 6f 20 73 65 | 74 20 74 68 65 20 74 74 |)) to se|t the tt|
|00004ef0| 79 20 74 6f 0a 69 74 73 | 20 6f 77 6e 20 70 72 6f |y to.its| own pro|
|00004f00| 63 65 73 73 20 67 72 6f | 75 70 2e 20 4e 6f 74 65 |cess gro|up. Note|
|00004f10| 20 74 68 61 74 20 69 74 | 20 68 61 73 20 74 6f 20 | that it| has to |
|00004f20| 69 67 6e 6f 72 65 20 53 | 49 47 54 54 4f 55 20 64 |ignore S|IGTTOU d|
|00004f30| 75 72 69 6e 67 20 74 68 | 69 73 0a 6f 70 65 72 61 |uring th|is.opera|
|00004f40| 74 69 6f 6e 2e 20 54 6f | 20 72 65 73 75 6d 65 20 |tion. To| resume |
|00004f50| 74 68 65 20 70 69 70 65 | 6c 69 6e 65 20 69 74 20 |the pipe|line it |
|00004f60| 64 6f 65 73 20 74 63 74 | 70 67 72 70 28 66 64 74 |does tct|pgrp(fdt|
|00004f70| 74 79 2c 70 69 64 29 20 | 77 68 65 72 65 20 70 69 |ty,pid) |where pi|
|00004f80| 64 0a 69 73 20 61 6e 79 | 20 6f 6e 65 20 6f 66 20 |d.is any| one of |
|00004f90| 74 68 65 20 63 68 69 6c | 64 20 70 72 6f 63 65 73 |the chil|d proces|
|00004fa0| 73 65 73 2c 20 74 68 65 | 6e 20 73 65 6e 64 73 20 |ses, the|n sends |
|00004fb0| 53 49 47 43 4f 4e 54 20 | 74 6f 20 74 68 65 20 70 |SIGCONT |to the p|
|00004fc0| 72 6f 63 65 73 73 0a 67 | 72 6f 75 70 2e 0a 58 0a |rocess.g|roup..X.|
|00004fd0| 53 74 61 72 74 69 6e 67 | 20 61 20 70 72 6f 63 65 |Starting| a proce|
|00004fe0| 73 73 20 75 6e 64 65 72 | 20 61 20 6e 65 77 20 74 |ss under| a new t|
|00004ff0| 74 79 3a 20 57 68 65 6e | 2c 20 66 6f 72 20 69 6e |ty: When|, for in|
|00005000| 73 74 61 6e 63 65 2c 20 | 74 65 6c 6e 65 74 64 20 |stance, |telnetd |
|00005010| 6f 72 0a 69 6e 69 74 2f | 67 65 74 74 79 20 6f 72 |or.init/|getty or|
|00005020| 20 61 6e 6f 74 68 65 72 | 20 70 72 6f 67 72 61 6d | another| program|
|00005030| 20 69 6e 20 70 72 6f 63 | 65 73 73 20 67 72 6f 75 | in proc|ess grou|
|00005040| 70 20 30 20 77 61 6e 74 | 73 20 74 6f 20 67 72 61 |p 0 want|s to gra|
|00005050| 62 20 61 20 74 74 79 2c | 20 69 74 0a 6f 70 65 6e |b a tty,| it.open|
|00005060| 73 20 74 68 65 20 74 74 | 79 20 61 6e 64 20 66 6f |s the tt|y and fo|
|00005070| 72 6b 73 20 61 20 63 68 | 69 6c 64 20 70 72 6f 63 |rks a ch|ild proc|
|00005080| 65 73 73 2e 20 54 68 65 | 20 63 68 69 6c 64 20 64 |ess. The| child d|
|00005090| 6f 65 73 20 74 63 6e 65 | 77 70 67 72 70 28 66 64 |oes tcne|wpgrp(fd|
|000050a0| 74 74 79 29 0a 74 6f 20 | 67 69 76 65 20 74 68 65 |tty).to |give the|
|000050b0| 20 74 74 79 20 61 20 72 | 65 61 6c 20 70 72 6f 63 | tty a r|eal proc|
|000050c0| 65 73 73 20 67 72 6f 75 | 70 2c 20 74 68 65 6e 20 |ess grou|p, then |
|000050d0| 73 65 74 74 70 67 72 70 | 28 66 64 74 74 79 29 20 |settpgrp|(fdtty) |
|000050e0| 74 6f 20 70 6c 61 63 65 | 0a 69 74 73 65 6c 66 20 |to place|.itself |
|000050f0| 69 6e 74 6f 20 74 68 65 | 20 66 6f 72 65 67 72 6f |into the| foregro|
|00005100| 75 6e 64 2e 0a 58 0a 43 | 68 61 6e 67 69 6e 67 20 |und..X.C|hanging |
|00005110| 74 74 79 73 3a 20 44 65 | 73 70 69 74 65 20 77 68 |ttys: De|spite wh|
|00005120| 61 74 20 50 4f 53 49 58 | 20 77 6f 75 6c 64 20 68 |at POSIX| would h|
|00005130| 61 76 65 20 79 6f 75 20 | 62 65 6c 69 65 76 65 20 |ave you |believe |
|00005140| 77 69 74 68 20 69 74 73 | 0a 73 65 73 73 69 6f 6e |with its|.session|
|00005150| 20 73 74 72 61 69 74 6a | 61 63 6b 65 74 20 72 75 | straitj|acket ru|
|00005160| 6c 65 73 2c 20 70 65 6f | 70 6c 65 20 64 6f 20 72 |les, peo|ple do r|
|00005170| 75 6e 20 70 72 6f 67 72 | 61 6d 73 20 61 6c 6c 20 |un progr|ams all |
|00005180| 74 68 65 20 74 69 6d 65 | 20 75 6e 64 65 72 20 61 |the time| under a|
|00005190| 0a 64 69 66 66 65 72 65 | 6e 74 20 74 74 79 20 66 |.differe|nt tty f|
|000051a0| 72 6f 6d 20 74 68 65 20 | 73 68 65 6c 6c 2e 20 54 |rom the |shell. T|
|000051b0| 68 65 20 6d 6f 73 74 20 | 63 6f 6d 6d 6f 6e 20 65 |he most |common e|
|000051c0| 78 61 6d 70 6c 65 20 69 | 6e 20 42 53 44 20 69 73 |xample i|n BSD is|
|000051d0| 20 70 72 6f 62 61 62 6c | 79 0a 74 68 65 20 73 63 | probabl|y.the sc|
|000051e0| 72 69 70 74 20 70 72 6f | 67 72 61 6d 3b 20 6f 74 |ript pro|gram; ot|
|000051f0| 68 65 72 20 65 78 61 6d | 70 6c 65 73 20 61 72 65 |her exam|ples are|
|00005200| 20 65 6d 61 63 73 2c 20 | 73 63 72 65 65 6e 2c 20 | emacs, |screen, |
|00005210| 70 74 79 2c 20 6d 74 74 | 79 2c 20 61 74 74 79 2e |pty, mtt|y, atty.|
|00005220| 0a 58 46 6f 72 74 75 6e | 61 74 65 6c 79 2c 20 65 |.XFortun|ately, e|
|00005230| 78 61 63 74 6c 79 20 74 | 68 65 20 73 61 6d 65 20 |xactly t|he same |
|00005240| 70 72 6f 63 65 64 75 72 | 65 20 77 6f 72 6b 73 20 |procedur|e works |
|00005250| 61 73 20 69 6e 20 74 68 | 65 20 70 72 65 76 69 6f |as in th|e previo|
|00005260| 75 73 0a 65 78 61 6d 70 | 6c 65 2e 0a 58 0a 44 69 |us.examp|le..X.Di|
|00005270| 73 73 6f 63 69 61 74 69 | 6e 67 20 61 20 64 61 65 |ssociati|ng a dae|
|00005280| 6d 6f 6e 3a 20 4e 6f 74 | 65 20 74 68 61 74 20 64 |mon: Not|e that d|
|00005290| 69 73 73 6f 63 69 61 74 | 69 6e 67 20 66 72 6f 6d |issociat|ing from|
|000052a0| 20 61 20 74 74 79 20 69 | 73 20 61 0a 63 6f 6e 74 | a tty i|s a.cont|
|000052b0| 72 6f 6c 6c 69 6e 67 2d | 74 65 72 6d 69 6e 61 6c |rolling-|terminal|
|000052c0| 20 63 6f 6e 63 65 70 74 | 2e 20 48 6f 77 65 76 65 | concept|. Howeve|
|000052d0| 72 2c 20 6d 6f 73 74 20 | 64 61 65 6d 6f 6e 73 20 |r, most |daemons |
|000052e0| 64 6f 20 77 61 6e 74 20 | 74 6f 20 70 6c 61 63 65 |do want |to place|
|000052f0| 0a 74 68 65 6d 73 65 6c | 76 65 73 20 69 6e 74 6f |.themsel|ves into|
|00005300| 20 70 72 6f 63 65 73 73 | 20 67 72 6f 75 70 73 20 | process| groups |
|00005310| 6f 66 20 74 68 65 69 72 | 20 6f 77 6e 2c 20 73 6f |of their| own, so|
|00005320| 20 74 68 61 74 20 74 68 | 65 79 20 61 72 65 20 6e | that th|ey are n|
|00005330| 6f 74 0a 61 66 66 65 63 | 74 65 64 20 62 79 20 6a |ot.affec|ted by j|
|00005340| 6f 62 2d 63 6f 6e 74 72 | 6f 6c 20 73 69 67 6e 61 |ob-contr|ol signa|
|00005350| 6c 73 2e 20 54 68 69 73 | 20 63 61 6e 20 62 65 20 |ls. This| can be |
|00005360| 68 61 6e 64 6c 65 64 20 | 69 6e 20 73 65 76 65 72 |handled |in sever|
|00005370| 61 6c 20 77 61 79 73 2c | 0a 62 75 74 20 62 79 20 |al ways,|.but by |
|00005380| 66 61 72 20 74 68 65 20 | 65 61 73 69 65 73 74 20 |far the |easiest |
|00005390| 69 73 20 73 65 74 74 70 | 67 72 70 28 2d 31 29 20 |is settp|grp(-1) |
|000053a0| 74 6f 20 6a 6f 69 6e 20 | 70 72 6f 63 65 73 73 20 |to join |process |
|000053b0| 67 72 6f 75 70 20 30 2e | 20 28 4e 6f 74 65 0a 74 |group 0.| (Note.t|
|000053c0| 68 61 74 20 75 6e 64 65 | 72 20 42 53 44 20 74 68 |hat unde|r BSD th|
|000053d0| 65 72 65 20 69 73 20 6e | 6f 20 72 65 6c 69 61 62 |ere is n|o reliab|
|000053e0| 6c 65 20 77 61 79 20 74 | 6f 20 64 69 73 73 6f 63 |le way t|o dissoc|
|000053f0| 69 61 74 65 20 66 72 6f | 6d 20 61 20 63 6f 6e 74 |iate fro|m a cont|
|00005400| 72 6f 6c 6c 69 6e 67 0a | 74 74 79 2d 2d 2d 74 68 |rolling.|tty---th|
|00005410| 65 20 54 49 4f 43 45 58 | 43 4c 20 69 6f 63 74 6c |e TIOCEX|CL ioctl|
|00005420| 20 63 61 6e 20 70 72 65 | 76 65 6e 74 20 64 69 73 | can pre|vent dis|
|00005430| 73 6f 63 69 61 74 69 6f | 6e 2e 20 54 68 61 74 20 |sociatio|n. That |
|00005440| 69 73 20 6e 6f 74 20 74 | 68 65 20 6d 61 72 6b 0a |is not t|he mark.|
|00005450| 6f 66 20 61 20 63 6c 65 | 61 6e 20 69 6e 74 65 72 |of a cle|an inter|
|00005460| 66 61 63 65 2e 29 0a 58 | 0a 58 46 6f 72 63 69 6e |face.).X|.XForcin|
|00005470| 67 20 6f 6e 65 73 65 6c | 66 20 69 6e 74 6f 20 74 |g onesel|f into t|
|00005480| 68 65 20 66 6f 72 65 67 | 72 6f 75 6e 64 3a 20 4d |he foreg|round: M|
|00005490| 6f 73 74 20 70 72 6f 67 | 72 61 6d 73 20 77 68 69 |ost prog|rams whi|
|000054a0| 63 68 20 6d 61 6e 69 70 | 75 6c 61 74 65 20 74 68 |ch manip|ulate th|
|000054b0| 65 0a 74 74 79 2c 20 75 | 73 75 61 6c 6c 79 20 73 |e.tty, u|sually s|
|000054c0| 6f 20 74 68 61 74 20 74 | 68 65 79 20 63 61 6e 20 |o that t|hey can |
|000054d0| 72 75 6e 20 69 6e 20 63 | 68 61 72 61 63 74 65 72 |run in c|haracter|
|000054e0| 20 6d 6f 64 65 2c 20 64 | 6f 6e 27 74 20 77 6f 72 | mode, d|on't wor|
|000054f0| 6b 0a 63 6f 72 72 65 63 | 74 6c 79 20 77 69 74 68 |k.correc|tly with|
|00005500| 20 6a 6f 62 20 63 6f 6e | 74 72 6f 6c 2e 20 54 68 | job con|trol. Th|
|00005510| 65 20 75 73 75 61 6c 20 | 73 65 71 75 65 6e 63 65 |e usual |sequence|
|00005520| 20 61 66 74 65 72 20 73 | 74 61 72 74 75 70 20 69 | after s|tartup i|
|00005530| 73 20 74 68 69 73 3a 0a | 72 65 61 64 20 74 74 79 |s this:.|read tty|
|00005540| 20 6d 6f 64 65 73 3b 20 | 77 72 69 74 65 20 6e 65 | modes; |write ne|
|00005550| 77 20 74 74 79 20 6d 6f | 64 65 73 20 69 6e 63 6c |w tty mo|des incl|
|00005560| 75 64 69 6e 67 20 6e 6f | 65 63 68 6f 20 61 6e 64 |uding no|echo and|
|00005570| 20 63 62 72 65 61 6b 2e | 20 54 68 65 0a 70 72 6f | cbreak.| The.pro|
|00005580| 62 6c 65 6d 20 69 73 20 | 74 68 61 74 20 74 68 65 |blem is |that the|
|00005590| 20 70 72 6f 63 65 73 73 | 20 63 6f 75 6c 64 20 62 | process| could b|
|000055a0| 65 20 69 6e 20 74 68 65 | 20 62 61 63 6b 67 72 6f |e in the| backgro|
|000055b0| 75 6e 64 20 77 68 65 6e | 20 69 74 20 72 65 61 64 |und when| it read|
|000055c0| 73 20 74 68 65 0a 74 74 | 79 20 6d 6f 64 65 73 2d |s the.tt|y modes-|
|000055d0| 2d 2d 61 20 64 69 66 66 | 65 72 65 6e 74 20 70 72 |--a diff|erent pr|
|000055e0| 6f 67 72 61 6d 2c 20 77 | 68 69 63 68 20 69 74 73 |ogram, w|hich its|
|000055f0| 65 6c 66 20 63 68 61 6e | 67 65 73 20 74 68 65 20 |elf chan|ges the |
|00005600| 74 74 79 20 6d 6f 64 65 | 73 20 74 6f 0a 73 6f 6d |tty mode|s to.som|
|00005610| 65 74 68 69 6e 67 20 73 | 74 72 61 6e 67 65 2c 20 |ething s|trange, |
|00005620| 63 6f 75 6c 64 20 62 65 | 20 69 6e 20 74 68 65 20 |could be| in the |
|00005630| 66 6f 72 65 67 72 6f 75 | 6e 64 2e 20 54 68 69 73 |foregrou|nd. This|
|00005640| 20 70 72 6f 63 65 73 73 | 20 77 69 6c 6c 20 72 65 | process| will re|
|00005650| 61 64 0a 74 68 65 20 73 | 74 72 61 6e 67 65 20 6d |ad.the s|trange m|
|00005660| 6f 64 65 73 2c 20 74 68 | 65 6e 20 73 74 6f 70 20 |odes, th|en stop |
|00005670| 77 68 65 6e 20 69 74 20 | 74 72 69 65 73 20 74 6f |when it |tries to|
|00005680| 20 73 65 74 20 74 68 65 | 20 6d 6f 64 65 73 2e 20 | set the| modes. |
|00005690| 4c 61 74 65 72 20 69 74 | 20 69 73 0a 72 65 73 74 |Later it| is.rest|
|000056a0| 61 72 74 65 64 20 61 6e | 64 20 72 75 6e 73 20 77 |arted an|d runs w|
|000056b0| 69 74 68 6f 75 74 20 74 | 72 6f 75 62 6c 65 2d 2d |ithout t|rouble--|
|000056c0| 2d 62 75 74 20 77 68 65 | 6e 20 69 74 20 65 78 69 |-but whe|n it exi|
|000056d0| 74 73 2c 20 69 74 20 77 | 69 6c 6c 0a 58 60 60 72 |ts, it w|ill.X``r|
|000056e0| 65 73 74 6f 72 65 27 27 | 20 74 68 65 20 74 74 79 |estore''| the tty|
|000056f0| 20 74 6f 20 74 68 6f 73 | 65 20 73 74 72 61 6e 67 | to thos|e strang|
|00005700| 65 20 6d 6f 64 65 73 20 | 69 74 20 73 74 61 72 74 |e modes |it start|
|00005710| 65 64 20 77 69 74 68 2e | 20 54 6f 20 61 76 6f 69 |ed with.| To avoi|
|00005720| 64 0a 74 68 69 73 20 62 | 75 67 2c 20 70 72 6f 63 |d.this b|ug, proc|
|00005730| 65 73 73 65 73 20 77 68 | 69 63 68 20 6d 61 6e 69 |esses wh|ich mani|
|00005740| 70 75 6c 61 74 65 20 74 | 68 65 20 74 74 79 20 73 |pulate t|he tty s|
|00005750| 68 6f 75 6c 64 20 66 6f | 72 63 65 20 74 68 65 6d |hould fo|rce them|
|00005760| 73 65 6c 76 65 73 0a 69 | 6e 74 6f 20 74 68 65 20 |selves.i|nto the |
|00005770| 66 6f 72 65 67 72 6f 75 | 6e 64 20 62 65 66 6f 72 |foregrou|nd befor|
|00005780| 65 20 72 65 61 64 69 6e | 67 20 6f 72 20 77 72 69 |e readin|g or wri|
|00005790| 74 69 6e 67 20 61 6e 79 | 74 68 69 6e 67 2e 20 41 |ting any|thing. A|
|000057a0| 6e 20 65 61 73 79 20 77 | 61 79 20 74 6f 0a 64 6f |n easy w|ay to.do|
|000057b0| 20 74 68 69 73 20 69 73 | 20 74 63 74 70 67 72 70 | this is| tctpgrp|
|000057c0| 28 67 65 74 70 69 64 28 | 29 29 2c 20 77 69 74 68 |(getpid(|)), with|
|000057d0| 20 74 68 65 20 64 65 66 | 61 75 6c 74 20 53 49 47 | the def|ault SIG|
|000057e0| 54 54 4f 55 20 68 61 6e | 64 6c 65 72 2e 20 4e 6f |TTOU han|dler. No|
|000057f0| 74 65 0a 74 68 61 74 20 | 74 68 65 20 70 72 6f 67 |te.that |the prog|
|00005800| 72 61 6d 20 73 68 6f 75 | 6c 64 20 61 6c 73 6f 20 |ram shou|ld also |
|00005810| 64 6f 20 74 68 69 73 20 | 75 70 6f 6e 20 63 6f 6e |do this |upon con|
|00005820| 74 69 6e 75 69 6e 67 20 | 61 66 74 65 72 20 61 20 |tinuing |after a |
|00005830| 73 74 6f 70 2d 2d 2d 0a | 6f 74 68 65 72 77 69 73 |stop---.|otherwis|
|00005840| 65 20 69 74 20 6d 69 67 | 68 74 20 6d 61 6b 65 20 |e it mig|ht make |
|00005850| 74 68 65 20 73 61 6d 65 | 20 6d 69 73 74 61 6b 65 |the same| mistake|
|00005860| 20 6f 66 20 72 65 61 64 | 69 6e 67 20 6d 6f 64 65 | of read|ing mode|
|00005870| 73 20 62 65 66 6f 72 65 | 20 69 74 0a 6b 6e 6f 77 |s before| it.know|
|00005880| 73 20 69 74 27 73 20 69 | 6e 20 74 68 65 20 66 6f |s it's i|n the fo|
|00005890| 72 65 67 72 6f 75 6e 64 | 2e 0a 58 0a 58 0a 58 31 |reground|..X.X.X1|
|000058a0| 30 2e 20 48 65 6c 70 66 | 75 6c 20 65 78 74 65 6e |0. Helpf|ul exten|
|000058b0| 73 69 6f 6e 73 20 74 6f | 20 74 68 65 20 6a 6f 62 |sions to| the job|
|000058c0| 20 63 6f 6e 74 72 6f 6c | 20 73 79 73 74 65 6d 0a | control| system.|
|000058d0| 58 0a 54 68 65 72 65 20 | 61 72 65 20 73 65 76 65 |X.There |are seve|
|000058e0| 72 61 6c 20 73 74 65 70 | 73 20 79 6f 75 20 63 61 |ral step|s you ca|
|000058f0| 6e 20 74 61 6b 65 20 77 | 68 69 63 68 20 64 6f 6e |n take w|hich don|
|00005900| 27 74 20 65 78 74 65 6e | 64 20 74 68 65 20 6a 6f |'t exten|d the jo|
|00005910| 62 20 63 6f 6e 74 72 6f | 6c 0a 69 6e 74 65 72 66 |b contro|l.interf|
|00005920| 61 63 65 20 62 75 74 20 | 77 68 69 63 68 20 64 6f |ace but |which do|
|00005930| 20 6d 61 6b 65 20 6a 6f | 62 20 63 6f 6e 74 72 6f | make jo|b contro|
|00005940| 6c 20 70 72 6f 67 72 61 | 6d 73 20 6d 6f 72 65 20 |l progra|ms more |
|00005950| 70 6f 72 74 61 62 6c 65 | 20 6f 72 20 65 61 73 69 |portable| or easi|
|00005960| 65 72 0a 74 6f 20 72 65 | 61 64 2e 0a 58 0a 41 73 |er.to re|ad..X.As|
|00005970| 20 6e 6f 74 65 64 20 61 | 62 6f 76 65 2c 20 42 53 | noted a|bove, BS|
|00005980| 44 20 68 61 73 20 61 20 | 77 61 69 74 33 28 29 20 |D has a |wait3() |
|00005990| 63 61 6c 6c 20 69 6e 73 | 74 65 61 64 20 6f 66 20 |call ins|tead of |
|000059a0| 77 61 69 74 32 28 29 2e | 20 49 74 20 69 73 20 63 |wait2().| It is c|
|000059b0| 61 6c 6c 65 64 0a 61 73 | 20 66 6f 6c 6c 6f 77 73 |alled.as| follows|
|000059c0| 3a 0a 58 0a 58 20 20 23 | 69 6e 63 6c 75 64 65 20 |:.X.X #|include |
|000059d0| 3c 73 79 73 2f 77 61 69 | 74 2e 68 3e 0a 58 20 20 |<sys/wai|t.h>.X |
|000059e0| 23 69 6e 63 6c 75 64 65 | 20 3c 73 79 73 2f 74 69 |#include| <sys/ti|
|000059f0| 6d 65 2e 68 3e 0a 58 20 | 20 23 69 6e 63 6c 75 64 |me.h>.X | #includ|
|00005a00| 65 20 3c 73 79 73 2f 72 | 65 73 6f 75 72 63 65 2e |e <sys/r|esource.|
|00005a10| 68 3e 0a 58 0a 58 20 20 | 69 6e 74 20 77 61 69 74 |h>.X.X |int wait|
|00005a20| 33 28 73 74 61 74 75 73 | 2c 6f 70 74 69 6f 6e 73 |3(status|,options|
|00005a30| 2c 72 75 73 61 67 65 29 | 0a 58 20 20 69 6e 74 20 |,rusage)|.X int |
|00005a40| 2a 73 74 61 74 75 73 3b | 0a 58 20 20 69 6e 74 20 |*status;|.X int |
|00005a50| 6f 70 74 69 6f 6e 73 3b | 0a 58 20 20 73 74 72 75 |options;|.X stru|
|00005a60| 63 74 20 72 75 73 61 67 | 65 20 2a 72 75 73 61 67 |ct rusag|e *rusag|
|00005a70| 65 3b 0a 58 0a 49 66 20 | 72 75 73 61 67 65 20 69 |e;.X.If |rusage i|
|00005a80| 73 20 4e 55 4c 4c 2c 20 | 74 68 69 73 20 69 73 20 |s NULL, |this is |
|00005a90| 6a 75 73 74 20 6c 69 6b | 65 20 77 61 69 74 32 28 |just lik|e wait2(|
|00005aa0| 29 2e 20 3c 73 79 73 2f | 74 69 6d 65 2e 68 3e 20 |). <sys/|time.h> |
|00005ab0| 63 61 6e 20 73 69 6d 70 | 6c 79 0a 58 23 69 6e 63 |can simp|ly.X#inc|
|00005ac0| 6c 75 64 65 20 3c 74 69 | 6d 65 2e 68 3e 2e 20 28 |lude <ti|me.h>. (|
|00005ad0| 55 6e 64 65 72 20 42 53 | 44 20 69 74 20 64 65 66 |Under BS|D it def|
|00005ae0| 69 6e 65 73 20 73 65 76 | 65 72 61 6c 20 73 79 73 |ines sev|eral sys|
|00005af0| 74 65 6d 20 74 69 6d 65 | 20 73 74 72 75 63 74 75 |tem time| structu|
|00005b00| 72 65 73 2c 0a 6c 69 6b | 65 20 73 74 72 75 63 74 |res,.lik|e struct|
|00005b10| 20 74 69 6d 65 76 61 6c | 2e 29 20 3c 73 79 73 2f | timeval|.) <sys/|
|00005b20| 72 65 73 6f 75 72 63 65 | 2e 68 3e 20 64 6f 65 73 |resource|.h> does|
|00005b30| 6e 27 74 20 6e 65 65 64 | 20 74 6f 20 70 72 6f 76 |n't need| to prov|
|00005b40| 69 64 65 20 61 6e 79 0a | 69 6e 66 6f 72 6d 61 74 |ide any.|informat|
|00005b50| 69 6f 6e 20 6f 74 68 65 | 72 20 74 68 61 6e 20 61 |ion othe|r than a|
|00005b60| 20 64 65 66 69 6e 69 74 | 69 6f 6e 20 6f 66 20 73 | definit|ion of s|
|00005b70| 74 72 75 63 74 20 72 75 | 73 61 67 65 2e 20 28 55 |truct ru|sage. (U|
|00005b80| 6e 64 65 72 20 42 53 44 | 2c 20 69 66 20 61 0a 63 |nder BSD|, if a.c|
|00005b90| 68 69 6c 64 20 65 78 69 | 74 73 20 61 6e 64 20 74 |hild exi|ts and t|
|00005ba0| 68 65 20 70 61 72 65 6e | 74 20 70 72 6f 76 69 64 |he paren|t provid|
|00005bb0| 65 73 20 61 20 6e 6f 6e | 2d 4e 55 4c 4c 20 72 75 |es a non|-NULL ru|
|00005bc0| 73 61 67 65 20 70 6f 69 | 6e 74 65 72 20 74 6f 0a |sage poi|nter to.|
|00005bd0| 77 61 69 74 33 28 29 2c | 20 74 68 65 20 73 74 72 |wait3(),| the str|
|00005be0| 75 63 74 75 72 65 20 69 | 73 20 66 69 6c 6c 65 64 |ucture i|s filled|
|00005bf0| 20 69 6e 20 77 69 74 68 | 20 69 6e 66 6f 72 6d 61 | in with| informa|
|00005c00| 74 69 6f 6e 20 61 62 6f | 75 74 20 74 68 65 20 72 |tion abo|ut the r|
|00005c10| 65 73 6f 75 72 63 65 73 | 0a 75 73 65 64 20 62 79 |esources|.used by|
|00005c20| 20 74 68 65 20 63 68 69 | 6c 64 20 5b 61 6e 64 20 | the chi|ld [and |
|00005c30| 69 74 73 20 63 68 69 6c | 64 72 65 6e 2c 20 61 6e |its chil|dren, an|
|00005c40| 64 20 73 6f 20 6f 6e 5d | 2e 20 46 6f 72 20 69 6e |d so on]|. For in|
|00005c50| 73 74 61 6e 63 65 2c 0a | 72 75 5f 6e 73 69 67 6e |stance,.|ru_nsign|
|00005c60| 61 6c 73 20 69 73 20 74 | 68 65 20 6e 75 6d 62 65 |als is t|he numbe|
|00005c70| 72 20 6f 66 20 73 69 67 | 6e 61 6c 73 20 72 65 63 |r of sig|nals rec|
|00005c80| 65 69 76 65 64 2e 20 54 | 68 69 73 20 69 73 20 76 |eived. T|his is v|
|00005c90| 65 72 79 20 6f 70 65 6e | 2d 65 6e 64 65 64 0a 61 |ery open|-ended.a|
|00005ca0| 6e 64 20 61 62 73 6f 6c | 75 74 65 6c 79 20 69 72 |nd absol|utely ir|
|00005cb0| 72 65 6c 65 76 61 6e 74 | 20 74 6f 20 6a 6f 62 20 |relevant| to job |
|00005cc0| 63 6f 6e 74 72 6f 6c 2e | 29 20 49 66 20 79 6f 75 |control.|) If you|
|00005cd0| 20 61 72 65 20 61 64 64 | 69 6e 67 20 6a 6f 62 20 | are add|ing job |
|00005ce0| 63 6f 6e 74 72 6f 6c 0a | 74 6f 20 61 20 73 79 73 |control.|to a sys|
|00005cf0| 74 65 6d 20 77 69 74 68 | 6f 75 74 20 69 74 20 61 |tem with|out it a|
|00005d00| 6e 64 20 77 61 6e 74 20 | 74 6f 20 70 72 6f 76 69 |nd want |to provi|
|00005d10| 64 65 20 74 68 65 20 77 | 61 69 74 33 28 29 20 63 |de the w|ait3() c|
|00005d20| 61 6c 6c 2c 20 6a 75 73 | 74 20 64 65 66 69 6e 65 |all, jus|t define|
|00005d30| 0a 73 74 72 75 63 74 20 | 72 75 73 61 67 65 20 7b |.struct |rusage {|
|00005d40| 20 69 6e 74 20 64 75 6d | 6d 79 3b 20 7d 2e 20 57 | int dum|my; }. W|
|00005d50| 68 69 6c 65 20 61 20 6a | 6f 62 2d 63 6f 6e 74 72 |hile a j|ob-contr|
|00005d60| 6f 6c 20 73 68 65 6c 6c | 20 63 61 6e 20 6d 61 6b |ol shell| can mak|
|00005d70| 65 20 67 6f 6f 64 0a 75 | 73 65 20 6f 66 20 72 65 |e good.u|se of re|
|00005d80| 73 6f 75 72 63 65 20 69 | 6e 66 6f 72 6d 61 74 69 |source i|nformati|
|00005d90| 6f 6e 2c 20 6d 6f 73 74 | 20 75 73 65 73 20 6f 66 |on, most| uses of|
|00005da0| 20 77 61 69 74 33 28 29 | 20 72 65 61 6c 6c 79 20 | wait3()| really |
|00005db0| 64 6f 6e 27 74 20 6e 65 | 65 64 20 74 68 65 0a 74 |don't ne|ed the.t|
|00005dc0| 68 69 72 64 20 61 72 67 | 75 6d 65 6e 74 2e 20 48 |hird arg|ument. H|
|00005dd0| 6f 77 65 76 65 72 2c 20 | 74 68 65 72 65 20 61 72 |owever, |there ar|
|00005de0| 65 20 65 6e 6f 75 67 68 | 20 70 72 6f 67 72 61 6d |e enough| program|
|00005df0| 73 20 77 68 69 63 68 20 | 69 6e 63 6c 75 64 65 0a |s which |include.|
|00005e00| 58 3c 73 79 73 2f 74 69 | 6d 65 2e 68 3e 20 61 6e |X<sys/ti|me.h> an|
|00005e10| 64 20 3c 73 79 73 2f 72 | 65 73 6f 75 72 63 65 2e |d <sys/r|esource.|
|00005e20| 68 3e 20 61 6e 64 20 75 | 73 65 20 77 61 69 74 33 |h> and u|se wait3|
|00005e30| 28 29 20 74 68 61 74 20 | 69 74 20 69 73 20 77 6f |() that |it is wo|
|00005e40| 72 74 68 77 68 69 6c 65 | 0a 74 6f 20 70 72 6f 76 |rthwhile|.to prov|
|00005e50| 69 64 65 20 74 68 65 20 | 65 78 74 72 61 20 69 6e |ide the |extra in|
|00005e60| 74 65 72 66 61 63 65 2e | 0a 58 0a 41 6e 6f 74 68 |terface.|.X.Anoth|
|00005e70| 65 72 20 65 78 74 65 6e | 73 69 6f 6e 20 69 73 20 |er exten|sion is |
|00005e80| 74 6f 20 64 65 66 69 6e | 65 20 61 20 60 60 75 6e |to defin|e a ``un|
|00005e90| 69 6f 6e 20 77 61 69 74 | 27 27 20 74 79 70 65 20 |ion wait|'' type |
|00005ea0| 69 6e 20 3c 73 79 73 2f | 77 61 69 74 2e 68 3e 0a |in <sys/|wait.h>.|
|00005eb0| 77 69 74 68 20 61 6e 20 | 60 60 69 6e 74 20 77 5f |with an |``int w_|
|00005ec0| 73 74 61 74 75 73 27 27 | 20 6d 65 6d 62 65 72 2e |status''| member.|
|00005ed0| 20 41 74 20 73 6f 6d 65 | 20 70 6f 69 6e 74 20 42 | At some| point B|
|00005ee0| 53 44 20 6c 65 66 74 20 | 74 68 65 20 62 65 61 74 |SD left |the beat|
|00005ef0| 65 6e 20 70 61 74 68 0a | 61 6e 64 20 64 65 63 69 |en path.|and deci|
|00005f00| 64 65 64 20 74 68 61 74 | 20 77 61 69 74 28 29 20 |ded that| wait() |
|00005f10| 73 68 6f 75 6c 64 20 75 | 73 65 20 61 20 75 6e 69 |should u|se a uni|
|00005f20| 6f 6e 20 77 61 69 74 20 | 69 6e 73 74 65 61 64 20 |on wait |instead |
|00005f30| 6f 66 20 61 6e 20 69 6e | 74 20 74 6f 0a 72 65 74 |of an in|t to.ret|
|00005f40| 75 72 6e 20 73 74 61 74 | 75 73 20 69 6e 66 6f 72 |urn stat|us infor|
|00005f50| 6d 61 74 69 6f 6e 2e 20 | 54 68 69 73 20 64 65 63 |mation. |This dec|
|00005f60| 69 73 69 6f 6e 20 69 73 | 20 67 65 6e 65 72 61 6c |ision is| general|
|00005f70| 6c 79 20 72 65 67 61 72 | 64 65 64 20 61 73 20 61 |ly regar|ded as a|
|00005f80| 0a 6d 69 73 74 61 6b 65 | 20 69 66 20 6f 6e 6c 79 |.mistake| if only|
|00005f90| 20 62 65 63 61 75 73 65 | 20 69 74 20 73 65 76 65 | because| it seve|
|00005fa0| 72 65 6c 79 20 68 61 6d | 70 65 72 73 20 70 6f 72 |rely ham|pers por|
|00005fb0| 74 61 62 69 6c 69 74 79 | 2c 20 62 75 74 20 74 68 |tability|, but th|
|00005fc0| 65 72 65 20 61 72 65 0a | 71 75 69 74 65 20 61 20 |ere are.|quite a |
|00005fd0| 66 65 77 20 70 72 6f 67 | 72 61 6d 73 20 77 68 69 |few prog|rams whi|
|00005fe0| 63 68 20 64 65 70 65 6e | 64 20 6f 6e 20 69 74 2c |ch depen|d on it,|
|00005ff0| 20 61 6e 64 20 74 68 65 | 72 65 27 73 20 6e 6f 20 | and the|re's no |
|00006000| 68 61 72 6d 20 69 6e 0a | 73 75 70 70 6f 72 74 69 |harm in.|supporti|
|00006010| 6e 67 20 69 74 2e 0a 58 | 0a 4d 6f 72 65 20 75 73 |ng it..X|.More us|
|00006020| 65 66 75 6c 20 69 73 20 | 74 6f 20 64 65 66 69 6e |eful is |to defin|
|00006030| 65 20 61 20 73 65 74 20 | 6f 66 20 6d 61 63 72 6f |e a set |of macro|
|00006040| 73 20 77 68 69 63 68 20 | 65 78 74 72 61 63 74 20 |s which |extract |
|00006050| 69 6e 66 6f 72 6d 61 74 | 69 6f 6e 20 66 72 6f 6d |informat|ion from|
|00006060| 0a 61 20 77 61 69 74 20 | 73 74 61 74 75 73 2e 20 |.a wait |status. |
|00006070| 28 55 6e 64 65 72 20 42 | 53 44 2c 20 75 6e 69 6f |(Under B|SD, unio|
|00006080| 6e 20 77 61 69 74 20 61 | 63 74 75 61 6c 6c 79 20 |n wait a|ctually |
|00006090| 63 6f 6e 74 61 69 6e 73 | 20 73 74 72 75 63 74 75 |contains| structu|
|000060a0| 72 65 0a 6d 65 6d 62 65 | 72 73 20 77 68 69 63 68 |re.membe|rs which|
|000060b0| 20 65 6e 63 6f 64 65 20 | 74 68 65 20 73 61 6d 65 | encode |the same|
|000060c0| 20 69 6e 66 6f 72 6d 61 | 74 69 6f 6e 2e 20 48 6f | informa|tion. Ho|
|000060d0| 77 65 76 65 72 2c 20 74 | 68 65 20 6d 61 63 72 6f |wever, t|he macro|
|000060e0| 73 20 61 72 65 0a 65 61 | 73 69 65 72 20 74 6f 20 |s are.ea|sier to |
|000060f0| 75 73 65 20 61 6e 64 20 | 73 75 70 70 6f 72 74 2e |use and |support.|
|00006100| 29 20 48 65 72 65 20 61 | 72 65 20 74 68 65 20 69 |) Here a|re the i|
|00006110| 6d 70 6f 72 74 61 6e 74 | 20 6f 6e 65 73 3a 0a 58 |mportant| ones:.X|
|00006120| 0a 58 20 20 20 23 64 65 | 66 69 6e 65 20 57 49 46 |.X #de|fine WIF|
|00006130| 53 54 4f 50 50 45 44 28 | 73 29 20 28 28 28 73 29 |STOPPED(|s) (((s)|
|00006140| 20 26 20 30 31 37 37 29 | 20 3d 3d 20 30 31 37 37 | & 0177)| == 0177|
|00006150| 29 0a 58 20 20 20 23 64 | 65 66 69 6e 65 20 57 49 |).X #d|efine WI|
|00006160| 46 45 58 49 54 45 44 28 | 73 29 20 28 21 28 28 73 |FEXITED(|s) (!((s|
|00006170| 29 20 26 20 30 31 37 37 | 29 29 0a 58 20 20 20 23 |) & 0177|)).X #|
|00006180| 64 65 66 69 6e 65 20 57 | 49 46 53 49 47 4e 41 4c |define W|IFSIGNAL|
|00006190| 45 44 28 73 29 20 28 30 | 31 37 36 20 3e 20 28 75 |ED(s) (0|176 > (u|
|000061a0| 6e 73 69 67 6e 65 64 29 | 20 28 28 28 73 29 20 26 |nsigned)| (((s) &|
|000061b0| 20 30 31 37 37 29 20 2d | 20 31 29 29 0a 58 20 20 | 0177) -| 1)).X |
|000061c0| 20 23 64 65 66 69 6e 65 | 20 57 53 54 4f 50 53 49 | #define| WSTOPSI|
|000061d0| 47 28 73 29 20 28 28 73 | 29 20 3e 3e 20 38 29 20 |G(s) ((s|) >> 8) |
|000061e0| 2f 2a 20 6f 6e 6c 79 20 | 64 65 66 69 6e 65 64 20 |/* only |defined |
|000061f0| 69 66 20 57 49 46 53 54 | 4f 50 50 45 44 20 2a 2f |if WIFST|OPPED */|
|00006200| 0a 58 20 20 20 23 64 65 | 66 69 6e 65 20 57 45 58 |.X #de|fine WEX|
|00006210| 49 54 53 54 41 54 55 53 | 28 73 29 20 28 28 73 29 |ITSTATUS|(s) ((s)|
|00006220| 20 3e 3e 20 38 29 20 2f | 2a 20 6f 6e 6c 79 20 64 | >> 8) /|* only d|
|00006230| 65 66 69 6e 65 64 20 69 | 66 20 57 49 46 45 58 49 |efined i|f WIFEXI|
|00006240| 54 45 44 20 2a 2f 0a 58 | 20 20 20 23 64 65 66 69 |TED */.X| #defi|
|00006250| 6e 65 20 57 54 45 52 4d | 53 49 47 28 73 29 20 28 |ne WTERM|SIG(s) (|
|00006260| 28 73 29 20 26 20 30 31 | 37 37 29 20 2f 2a 20 6f |(s) & 01|77) /* o|
|00006270| 6e 6c 79 20 64 65 66 69 | 6e 65 64 20 69 66 20 57 |nly defi|ned if W|
|00006280| 49 46 53 49 47 4e 41 4c | 45 44 20 2a 2f 0a 58 20 |IFSIGNAL|ED */.X |
|00006290| 20 20 23 64 65 66 69 6e | 65 20 57 43 4f 52 45 44 | #defin|e WCORED|
|000062a0| 55 4d 50 28 73 29 20 28 | 28 73 29 20 26 20 30 32 |UMP(s) (|(s) & 02|
|000062b0| 30 30 29 20 2f 2a 20 6f | 6e 6c 79 20 64 65 66 69 |00) /* o|nly defi|
|000062c0| 6e 65 64 20 69 66 20 57 | 49 46 53 49 47 4e 41 4c |ned if W|IFSIGNAL|
|000062d0| 45 44 20 2a 2f 0a 58 0a | 4f 6e 20 73 6f 6d 65 20 |ED */.X.|On some |
|000062e0| 31 36 2d 62 69 74 20 6d | 61 63 68 69 6e 65 73 20 |16-bit m|achines |
|000062f0| 74 68 65 20 3e 3e 20 38 | 20 6d 61 79 20 68 61 76 |the >> 8| may hav|
|00006300| 65 20 74 6f 20 62 65 20 | 63 68 61 6e 67 65 64 2c |e to be |changed,|
|00006310| 20 6f 72 20 28 73 29 20 | 6d 61 79 20 68 61 76 65 | or (s) |may have|
|00006320| 0a 74 6f 20 62 65 20 63 | 61 73 74 20 74 6f 20 75 |.to be c|ast to u|
|00006330| 6e 73 69 67 6e 65 64 2e | 20 54 68 65 73 65 20 6d |nsigned.| These m|
|00006340| 61 63 72 6f 73 20 61 72 | 65 20 6d 65 61 6e 74 20 |acros ar|e meant |
|00006350| 74 6f 20 62 65 20 61 70 | 70 6c 69 65 64 20 74 6f |to be ap|plied to|
|00006360| 20 61 6e 20 69 6e 74 2c | 0a 6e 6f 74 20 61 20 75 | an int,|.not a u|
|00006370| 6e 69 6f 6e 20 77 61 69 | 74 3b 20 6d 6f 73 74 20 |nion wai|t; most |
|00006380| 63 6f 6d 70 69 6c 65 72 | 73 20 77 69 6c 6c 20 64 |compiler|s will d|
|00006390| 6f 20 74 68 65 20 72 69 | 67 68 74 20 74 68 69 6e |o the ri|ght thin|
|000063a0| 67 20 61 6e 79 77 61 79 | 2c 20 62 75 74 20 62 65 |g anyway|, but be|
|000063b0| 0a 63 61 72 65 66 75 6c | 2e 0a 58 0a 58 0a 41 63 |.careful|..X.X.Ac|
|000063c0| 6b 6e 6f 77 6c 65 64 67 | 6d 65 6e 74 73 0a 58 0a |knowledg|ments.X.|
|000063d0| 54 68 61 6e 6b 73 20 74 | 6f 20 43 68 72 69 73 20 |Thanks t|o Chris |
|000063e0| 54 6f 72 65 6b 2c 20 43 | 68 72 69 73 74 6f 73 20 |Torek, C|hristos |
|000063f0| 53 2e 20 5a 6f 75 6c 61 | 73 2c 20 61 6e 64 20 44 |S. Zoula|s, and D|
+--------+-------------------------+-------------------------+--------+--------+
Only 25.0 KB of data is shown above.