UNIXϵͳΪ³ÌÐòÔ±ÌṩÁËÐí¶à×Ó³ÌÐò,ÕâЩ×Ó³ÌÐò¿É´æÈ¡¸÷ÖÖ°²È«ÊôÐÔ.ÓÐ
ЩÊÇÐÅÏ¢×Ó³ÌÐò,·µ»ØÎļþÊôÐÔ,ʵ¼ÊµÄºÍÓÐЧµÄUID,GIDµÈÐÅÏ¢.ÓÐЩ×Ó³ÌÐò¿É
¸Ä±äÎļþÊôÐÔ.UID,GIDµÈÓÐЩ´¦Àí¿ÚÁîÎļþºÍС×éÎļþ,»¹ÓÐЩÍê³É¼ÓÃܺͽâÃÜ.
±¾ÎÄÖ÷ÒªÌÖÂÛÓйØϵͳ×Ó³ÌÐò,±ê×¼C¿â×Ó³ÌÐòµÄ°²È«,ÈçºÎд°²È«µÄC³ÌÐò
²¢´ÓrootµÄ½Ç¶È½éÉܳÌÐòÉè¼Æ(½öÄܱ»rootµ÷ÓõÄ×Ó³ÌÐò).
1.ϵͳ×Ó³ÌÐò
(1)I/O×Ó³ÌÐò
*creat():½¨Á¢Ò»¸öÐÂÎļþ»òÖØдһ¸öÔÝ´æÎļþ.
ÐèÒªÁ½¸ö²ÎÊý:ÎļþÃûºÍ´æÈ¡Ðí¿ÉÖµ(8½øÖÆ·½Ê½).Èç:
creat(""/usr/pat/read_write"",0666) /* ½¨Á¢´æÈ¡Ðí¿É·½Ê½Îª0666µÄÎļþ */
µ÷ÓôË×Ó³ÌÐòµÄ½ø³Ì±ØÐëÒªÓн¨Á¢µÄÎļþµÄËùÔÚĿ¼µÄдºÍÖ´ÐÐÐí¿É,ÖÃ
¸øcreat()µÄÐí¿É·½Ê½±äÁ¿½«±»umask()ÉèÖõÄÎļþ½¨Á¢ÆÁ±ÎÖµËùÐÞ¸Ä,ÐÂ
ÎļþµÄËùÓÐÕߺÍС×éÓÉÓÐЧµÄUIDºÍGID¾ö¶¨.
·µ»ØֵΪн¨ÎļþµÄÎļþÃèÊö·û.
*fstat():¼ûºóÃæµÄstat().
*open():ÔÚC³ÌÐòÄÚ²¿´ò¿ªÎļþ.
ÐèÒªÁ½¸ö²ÎÊý:Îļþ·¾¶ÃûºÍ´ò¿ª·½Ê½(I,O,I&O).
Èç¹ûµ÷ÓôË×Ó³ÌÐòµÄ½ø³ÌûÓжÔÓÚÒª´ò¿ªµÄÎļþµÄÕýÈ·´æÈ¡Ðí¿É(°üÀ¨ÎÄ
¼þ·¾¶ÉÏËùÓÐĿ¼·ÖÁ¿µÄËÑË÷Ðí¿É),½«»áÒýÆðÖ´ÐÐʧ°Ü.
Èç¹û´Ë×Ó³ÌÐò±»µ÷ÓÃÈ¥´ò¿ª²»´æÔÚµÄÎļþ,³ý·ÇÉèÖÃÁËO_CREAT±êÖ¾,µ÷ÓÃ
½«²»³É¹¦.´Ëʱ,ÐÂÎļþµÄ´æÈ¡Ðí¿É×÷ΪµÚÈý¸ö²ÎÊý(¿É±»Óû§µÄumaskÐÞ
¸Ä).
µ±Îļþ±»½ø³Ì´ò¿ªºóÔٸıä¸ÃÎļþ»ò¸ÃÎļþËùÔÚĿ¼µÄ´æÈ¡Ðí¿É,²»Ó°Ïì
¶Ô¸ÃÎļþµÄI/O²Ù×÷.
*read():´ÓÒÑÓÉopen()´ò¿ª²¢ÓÃ×÷ÊäÈëµÄÎļþÖжÁÐÅÏ¢.
Ëü²¢²»¹ØÐĸÃÎļþµÄ´æÈ¡Ðí¿É.Ò»µ©Îļþ×÷ΪÊäÈë´ò¿ª,¼´¿É´Ó¸ÃÎļþÖжÁ
È¡ÐÅÏ¢.
*write():Êä³öÐÅÏ¢µ½ÒÑÓÉopen()´ò¿ª²¢ÓÃ×÷Êä³öµÄÎļþÖÐ.ͬread()Ò»Ñù
ËüÒ²²»¹ØÐĸÃÎļþµÄ´æÈ¡Ðí¿É.
(2)½ø³Ì¿ØÖÆ
*exec()×å:°üÀ¨execl(),execv(),execle(),execve(),execlp()ºÍexecvp()
¿É½«Ò»¿ÉÖ´ÐÐÄ£¿ì¿½±´µ½µ÷Óýø³ÌÕ¼ÓеĴæÖü¿Õ¼ä.Õý±»µ÷Óýø
³ÌÖ´ÐеijÌÐò½«²»¸´´æÔÚ,гÌÐòÈ¡´úÆäλÖÃ.
ÕâÊÇUNIXϵͳÖÐÒ»¸ö³ÌÐò±»Ö´ÐеÄΨһ·½Ê½:Óý«Ö´ÐеijÌÐò¸´¸ÇÔÓеÄ
³ÌÐò.
°²È«×¢ÒâÊÂÏî:
. ʵ¼ÊµÄºÍÓÐЧµÄUIDºÍGID´«µÝ¸øÓÉexec()µ÷ÈëµÄ²»¾ßÓÐSUIDºÍSGIDÐí
¿ÉµÄ³ÌÐò.
. Èç¹ûÓÉexec()µ÷ÈëµÄ³ÌÐòÓÐSUIDºÍSGIDÐí¿É,ÔòÓÐЧµÄUIDºÍGID½«Éè
Öøø¸Ã³ÌÐòµÄËùÓÐÕß»òС×é.
. Îļþ½¨Á¢ÆÁ±ÎÖµ½«´«µÝ¸øгÌÐò.
. ³ýÉèÁ˶Ôexec()¹Ø±Õ±êÖ¾µÄÎļþÍâ,ËùÓдò¿ªµÄÎļþ¶¼´«µÝ¸øгÌÐò.
ÓÃfcntl()×Ó³ÌÐò¿ÉÉèÖöÔexec()µÄ¹Ø±Õ±êÖ¾.
*fork():ÓÃÀ´½¨Á¢Ð½ø³Ì.Æ佨Á¢µÄ×Ó½ø³ÌÊÇÓëµ÷ÓÃfork()µÄ½ø³Ì(¸¸½ø³Ì)
ÍêÈ«ÏàͬµÄ¿½±´(³ýÁ˽ø³ÌºÅÍâ)
°²È«×¢ÒâÊÂÏî:
. ×Ó½ø³Ì½«¼Ì³Ð¸¸½ø³ÌµÄʵ¼ÊºÍÓÐЧµÄUIDºÍGID.
. ×Ó½ø³Ì¼Ì³ÐÎļþ·½Ê½½¨Á¢ÆÁ±ÎÖµ.
. ËùÓдò¿ªµÄÎļþ´«¸ø×Ó½ø³Ì.
*signal():ÔÊÐí½ø³Ì´¦Àí¿ÉÄÜ·¢ÉúµÄÒâÍâʼþºÍÖжÏ.
ÐèÒªÁ½¸ö²ÎÊý:ÐźűàºÅºÍÐźŷ¢ÉúʱҪµ÷ÓõÄ×Ó³ÌÐò.
ÐźűàºÅ¶¨ÒåÔÚsignal.hÖÐ.
Ðźŷ¢ÉúʱҪµ÷ÓõÄ×Ó³ÌÐò¿ÉÓÉÓû§±àд,Ò²¿ÉÓÃϵͳ¸øµÄÖµ,Èç:SIG_IGN
ÔòÐźŽ«±»ºöÂÔ,SIG_DFLÔòÐźŽ«°´ÏµÍ³µÄȱʡ·½Ê½´¦Àí.
ÈçÐí¶àÓ밲ȫÓйصijÌÐò½ûÖ¹Öն˷¢ÖжÏÐÅÏ¢(BREAKºÍDELETE),ÒÔÃâ×Ô¼º
±»Óû§ÖÕ¶ËÖÕÖ¹ÔËÐÐ.
ÓÐЩÐźÅʹUNIXϵͳµÄ²úÉú½ø³ÌµÄºËÐÄת´¢(½ø³Ì½ÓÊÕµ½ÐźÅʱËùÕ¼ÄÚ´æ
µÄÄÚÈÝ,ÓÐʱº¬ÓÐÖØÒªÐÅÏ¢),´Ëϵͳ×Ó³ÌÐò¿ÉÓÃÓÚ½ûÖ¹ºËÐÄת´¢.
(3)ÎļþÊôÐÔ
*access():¼ì²âÖ¸¶¨ÎļþµÄ´æÈ¡ÄÜÁ¦ÊÇ·ñ·ûºÏÖ¸¶¨µÄ´æÈ¡ÀàÐÍ.
ÐèÒªÁ½¸ö²ÎÊý:ÎļþÃûºÍÒª¼ì²âµÄ´æÈ¡ÀàÐÍ(ÕûÊý).
ÏÂÃ滹ÓÐภ(19%) ©¦ ½áÊø ¡û ©¦ ¡ü/¡ý/PgUp/PgDn Òƶ¯ ©¦ ? ¸¨Öú˵Ã÷ ©¦
ÐèÒªÁ½¸ö²ÎÊý:ÎļþÃûºÍÒª¼ì²âµÄ´æÈ¡ÀàÐÍ(ÕûÊý).
´æÈ¡ÀàÐͶ¨ÒåÈçÏÂ:
0: ¼ì²éÎļþÊÇ·ñ´æÔÚ
1: ¼ì²éÊÇ·ñ¿ÉÖ´ÐÐ(ËÑË÷)
2: ¼ì²éÊÇ·ñ¿Éд
3: ¼ì²éÊÇ·ñ¿ÉдºÍÖ´ÐÐ
4: ¼ì²éÊÇ·ñ¿É¶Á
5: ¼ì²éÊÇ·ñ¿É¶ÁºÍÖ´ÐÐ
6: ¼ì²éÊÇ·ñ¿É¶Á¿Éд¿ÉÖ´ÐÐ
ÕâЩÊý×ÖµÄÒâÒåºÍchmodÃüÁîÖй涨Ðí¿É·½Ê½µÄÊý×ÖÒâÒåÏàͬ.
´Ë×Ó³ÌÐòʹÓÃʵ¼ÊµÄUIDºÍGID¼ì²âÎļþµÄ´æÈ¡ÄÜÁ¦(Ò»°ãÓÐЧµÄUIDºÍGID
ÓÃÓÚ¼ì²éÎļþ´æÈ¡ÄÜÁ¦).
·µ»ØÖµ: 0:Ðí¿É -1:²»Ðí¿É.
*chmod():½«Ö¸¶¨Îļþ»òĿ¼µÄ´æÈ¡Ðí¿É·½Ê½¸Ä³ÉеÄÐí¿É·½Ê½.
ÐèÒªÁ½¸ö²ÎÊý:ÎļþÃûºÍеĴæÈ¡Ðí¿É·½Ê½.
*chown():ͬʱ¸Ä±äÖ¸¶¨ÎļþµÄËùÓÐÕߺÍС×éµÄUIDºÍGID.(ÓëchownÃüÁî²»
ͬ).
ÓÉÓÚ´Ë×Ó³ÌÐòͬʱ¸Ä±äÎļþµÄËùÓÐÕߺÍС×é,¹Ê±ØÐëÈ¡ÏûËù²Ù×÷ÎļþµÄSUID
ºÍSGIDÐí¿É,ÒÔ·ÀÖ¹Óû§½¨Á¢SUIDºÍSGID³ÌÐò,È»ºóÔËÐÐchown()È¥»ñµÃ±ð
È˵ÄȨÏÞ.
*stat():·µ»ØÎļþµÄ״̬(ÊôÐÔ).
ÐèÒªÁ½¸ö²ÎÊý:Îļþ·¾¶ÃûºÍÒ»¸ö½á¹¹Ö¸Õë,Ö¸Ïò״̬ÐÅÏ¢µÄ´æ·Å
µÄλÖÃ.
½á¹¹¶¨ÒåÈçÏÂ:
st_mode: ÎļþÀàÐͺʹæÈ¡Ðí¿É·½Ê½
st_ino: I½ÚµãºÅ
st_dev: ÎļþËùÔÚÉ豸µÄID
st_rdev: ÌرðÎļþµÄID
st_nlink: ÎļþÁ´½ÓÊý
st_uid: ÎļþËùÓÐÕßµÄUID
st_gid: ÎļþС×éµÄGID
st_size: °´×Ö½Ú¼ÆÊýµÄÎļþ´óС
st_atime: ×îºó´æȡʱ¼ä(¶Á)
st_mtime: ×îºóÐÞ¸Äʱ¼ä(д)ºÍ×îºó״̬µÄ¸Ä±ä
st_ctime: ×îºóµÄ״̬ÐÞ¸Äʱ¼ä
·µ»ØÖµ: 0:³É¹¦ 1:ʧ°Ü
*umask():½«µ÷Óýø³Ì¼°Æä×Ó½ø³ÌµÄÎļþ½¨Á¢ÆÁ±ÎÖµÉèÖÃΪָ¶¨µÄ´æÈ¡Ðí¿É.
ÐèÒªÒ»¸ö²ÎÊý: еÄÎļþ½¨Á¢ÆÁÖµ.
(4)UIDºÍGIDµÄ´¦Àí
*getuid():·µ»Ø½ø³ÌµÄʵ¼ÊUID.
*getgid():·µ»Ø½ø³ÌµÄʵ¼ÊGID.
ÒÔÉÏÁ½¸ö×Ó³ÌÐò¿ÉÓÃÓÚÈ·¶¨ÊÇËÔÚÔËÐнø³Ì.
*geteuid():·µ»Ø½ø³ÌµÄÓÐЧUID.
*getegid():·µ»Ø½ø³ÌµÄÓÐЧGID.
ÒÔÉÏÁ½¸ö×Ó³ÌÐò¿ÉÔÚÒ»¸ö³ÌÐò²»µÃ²»È·¶¨ËüÊÇ·ñÔÚÔËÐÐijÓû§¶ø²»ÊÇÔËÐÐ
ËüµÄÓû§µÄSUID³ÌÐòʱºÜÓÐÓÃ,¿Éµ÷ÓÃËüÃÇÀ´¼ì²éÈ·Èϱ¾³ÌÐòµÄÈ·ÊÇÒÔ¸Ã
Óû§µÄSUIDÐí¿ÉÔÚÔËÐÐ.
*setuid():ÓÃÓڸıäÓÐЧµÄUID.
¶ÔÓÚÒ»°ãÓû§,´Ë×Ó³ÌÐò½ö¶ÔÒªÔÚÓÐЧºÍʵ¼ÊµÄUIDÖ®¼ä±ä»»µÄSUID³ÌÐò²Å
ÓÐÓÃ(´ÓÔÓÐЧUID±ä»»ÎªÊµ¼ÊUID),ÒÔ±£»¤½ø³Ì²»Êܵ½°²È«Î£º¦.ʵ¼ÊÉϸÃ
½ø³Ì²»ÔÙÊÇSUID·½Ê½ÔËÐÐ.
*setgid():ÓÃÓڸıäÓÐЧµÄGID.