]]>APUE2璇諱功絎旇(浜?:涓轟粈涔堟湁浜唚ait鍑芥暟鏃忚繕闇瑕丼IGCHLD淇″彿http://m.shnenglu.com/converse/archive/2007/12/28/39870.html鍒?/dc:creator>鍒?/author>Fri, 28 Dec 2007 15:39:00 GMThttp://m.shnenglu.com/converse/archive/2007/12/28/39870.htmlhttp://m.shnenglu.com/converse/comments/39870.htmlhttp://m.shnenglu.com/converse/archive/2007/12/28/39870.html#Feedback0http://m.shnenglu.com/converse/comments/commentRss/39870.htmlhttp://m.shnenglu.com/converse/services/trackbacks/39870.htmlIn UNIX System terminology, a process that has terminated, but whose parent has not yet waited for it, is called a zombie. 涔熷氨鏄,浣嗗嚒鏄埗榪涚▼娌℃湁璋冪敤wait鍑芥暟鑾峰緱瀛愯繘紼嬬粓姝㈢姸鎬佺殑瀛愯繘紼嬪湪緇堟涔嬪悗閮芥槸鍍靛案榪涚▼,榪欎釜姒傚康鐨勫叧閿竴鐐瑰氨鏄埗榪涚▼鏄惁璋冪敤浜唚ait鍑芥暟.
鑰屽叧浜嶴IGCHLD淇″彿,APUE2涓張濡傛槸璇? Whenever a process terminates or stops, the SIGCHLD signal is sent to the parent. By default, this signal is ignored, so the parent must catch this signal if it wants to be notified whenever a child's status changes. The normal action in the signal-catching function is to call one of the wait functions to fetch the child's process ID and termination status. 綆鍗曠殑璇?瀛愯繘紼嬮鍑烘椂鐖惰繘紼嬩細鏀跺埌涓涓猄IGCHLD淇″彿,榛樿鐨勫鐞嗘槸蹇界暐榪欎釜淇″彿,鑰屽父瑙勭殑鍋氭硶鏄湪榪欎釜淇″彿澶勭悊鍑芥暟涓皟鐢╳ait鍑芥暟鑾峰彇瀛愯繘紼嬬殑閫鍑虹姸鎬?
]]>APUE2璇諱功絎旇(涓):real user ID, effective user ID,saved set-user-ID http://m.shnenglu.com/converse/archive/2007/12/20/39166.html鍒?/dc:creator>鍒?/author>Thu, 20 Dec 2007 15:24:00 GMThttp://m.shnenglu.com/converse/archive/2007/12/20/39166.htmlhttp://m.shnenglu.com/converse/comments/39166.htmlhttp://m.shnenglu.com/converse/archive/2007/12/20/39166.html#Feedback0http://m.shnenglu.com/converse/comments/commentRss/39166.htmlhttp://m.shnenglu.com/converse/services/trackbacks/39166.htmlUnix涓父瑙佺殑鍑犱釜姒傚康,涓嬮潰鍋氫竴涓В閲?
棣栧厛闇瑕佹槑紜竴鐐?榪欏嚑涓蹇甸兘鏄拰榪涚▼鐩稿叧鐨? real user ID琛ㄧず鐨勬槸瀹為檯涓婅繘紼嬬殑鎵ц鑰呮槸璋?effective user ID涓昏鐢ㄤ簬鏍¢獙璇ヨ繘紼嬪湪鎵ц鏃舵墍鑾峰緱鐨勬枃浠惰闂潈闄?涔熷氨鏄褰撹繘紼嬭闂枃浠舵椂媯鏌ユ潈闄愭椂瀹為檯涓婃鏌ョ殑璇ヨ繘紼嬬殑"effective user ID",saved set-user-ID 浠呭湪effective user ID鍙戠敓鏀瑰彉鏃朵繚瀛?
涓鑸儏鍐典笅,real user ID灝辨槸榪涚▼鐨別ffective user ID,浣嗘槸褰撹榪愯鐨勫彲鎵ц紼嬪簭璁劇疆浜?set-user-ID"浣嶄箣鍚?榪涚▼鐨別ffective user ID鍙樻垚璇ユ枃浠剁殑灞炰富鐢ㄦ埛id,鍚屾椂璇ヨ繘紼嬬殑"saved set-user-ID"鍙樻垚姝ゆ椂榪涚▼鐨?effective user ID",涔熷氨鏄鍙墽琛岀▼搴忕殑灞炰富鐢ㄦ埛ID,璇ヨ繘紼嬪湪鎵ц涓浜涗笌鏂囦歡璁塊棶鏉冮檺鐩稿叧鐨勬搷浣滄椂緋葷粺媯鏌ョ殑鏄繘紼嬬殑effective user ID.
涓轟粈涔堥渶瑕佷竴涓?saved set-user-ID"?鍥犱負褰撹繘紼嬫病鏈夎秴綰х敤鎴鋒潈闄愮殑鏃跺?榪涚▼鍦ㄨ緗?effective user ID"鏃墮渶瑕佸皢闇瑕佽緗殑ID鍜岃榪涚▼鐨?real user ID"鎴栬?saved set-user-ID"榪涜姣旇緝.
APUE2涓繘琛岀殑瑙i噴鏄? 1)If the process has superuser privileges, the setuid function sets the real user ID, effective user ID, and saved set-user-ID to uid.
2)If the process does not have superuser privileges, but uid equals either the real user ID or the saved set-user-ID, setuid sets only the effective user ID to uid. The real user ID and the saved set-user-ID are not changed.
3)If neither of these two conditions is true, errno is set to EPERM, and 1 is returned 涔熷氨鏄: 1)褰撶敤鎴峰叿鏈夎秴綰х敤鎴鋒潈闄愮殑鏃跺?setuid 鍑芥暟璁劇疆鐨刬d瀵逛笁鑰呴兘璧鋒晥. 2)鍚﹀垯,浠呭綋璇d涓簉eal user ID 鎴栬卻aved set-user-ID鏃?璇d瀵筫ffective user ID璧鋒晥. 3)鍚﹀垯,setuid鍑芥暟璋冪敤澶辮觸.
涔熷氨鏄,榪欎釜saved set-user-ID鏇村鐨勪綔鐢ㄦ槸鍦ㄨ繘紼嬪垏鎹㈣嚜宸辯殑effective user ID璧蜂綔鐢?
闇瑕佺壒鍒彁閱掔殑鏄?騫舵病鏈変換浣曠殑API鍙互鑾峰彇鍒拌繘紼嬬殑saved set-user-ID,瀹冧粎浠呮槸緋葷粺鍦ㄨ皟鐢╯etuid鍑芥暟鏃惰繘琛屾瘮杈冭岃搗浣滅敤鐨? APUE2涓叧浜庢浜嬬殑鍘熻瘽濡備笅: Note that we can obtain only the current value of the real user ID and the effective user ID with the functions getuid and geteuid from Section 8.2. We can't obtain the current value of the saved set-user-ID.
褰揂鐢ㄦ埛鎵ц紼嬪簭proc鏃? 紼嬪簭鐨剅eal user ID = A鐨勭敤鎴稩D,effective user ID = B鐨勭敤鎴稩D, saved set-user-ID=B鐨勭敤鎴稩D.
鍋囧鍦ㄨ榪涚▼緇撴潫浜嗗鏌愪簺闄愬埗鍙兘鐢辯敤鎴稡璁塊棶鐨勬枃浠舵搷浣滃悗,紼嬪簭灝唀ffective user ID璁劇疆鍥濧,涔熷氨鏄姝ゆ椂: 紼嬪簭鐨剅eal user ID = A鐨勭敤鎴稩D,effective user ID = A鐨勭敤鎴稩D, saved set-user-ID=B鐨勭敤鎴稩D.
榪欎釜鏀瑰姩涔嬫墍浠ヨ兘鎴愬姛,鍘熷洜鍦ㄤ簬涓婇潰鍒椾婦鍑虹殑鎯呭喌2):璇D涓鴻繘紼嬬殑real user ID.
鏈鍚?鍋囪鐢變簬縐嶇鍘熷洜榪涚▼闇瑕佸啀嬈″垏鎹ffective user ID涓築,鍙槸鍥犱負涓嶈兘閫氳繃API鑾峰彇榪涚▼鐨剆aved set-user-ID(璇ュ間負B鐨勭敤鎴稩D),鎵浠ュ彧鑳介氳繃涓ょ閫斿緞鑾峰緱(鍙兘榪樻湁鍒殑閫斿緞): a)鍦ㄨ緗甧ffective user ID鍙樺洖A涔嬪墠淇濆瓨effective user ID,瀹冪殑鍊間負B鐨勭敤鎴稩D. b)璋冪敤鍑芥暟getpwnam( "B"),鍦ㄨ繑鍥炵殑struct passwd *鎸囬拡涓垚鍛榩w_uid瀛樻斁鐨勫氨鏄敤鎴稡鐨処D. 榪欐牱,榪欎釜璋冪敤setuid(B鐨勭敤鎴稩D)灝變細鎴愬姛,鍘熷洜涔熷湪浜庝笂闈㈣鐨勬儏鍐?):璇D涓庤繘紼嬬殑saved set-user-ID鐩稿悓.