乡下人产国偷v产偷v自拍,国产午夜片在线观看,婷婷成人亚洲综合国产麻豆,久久综合给合久久狠狠狠9

  • <output id="e9wm2"></output>
    <s id="e9wm2"><nobr id="e9wm2"><ins id="e9wm2"></ins></nobr></s>

    • 分享

      linux下的umask( )函數(shù)、setsid( )函數(shù)

       fym0121 2011-01-08

      linux下的umask()函數(shù)
      此函數(shù)的主要作用是在創(chuàng)建文件時(shí)設(shè)置或者屏蔽掉文件的一些權(quán)限。一般與open()函數(shù)配合使用。
      open函數(shù)原型:
      #include<sys/types.h>
      #include<sys/stat.h>
      #include<fcntl.h>
      int open( const char * pathname, int flags);
      int open( const char * pathname,int flags, mode_t mode);
      當(dāng)創(chuàng)建一個(gè)文件并且要明確指定此文件的權(quán)限時(shí),應(yīng)該使用第二個(gè)open()函數(shù),明確指定mode參數(shù),所創(chuàng)建的文件最后的權(quán)限是:mode&(~mask)。默認(rèn)的mask值是:022
      例:
      #include <sys/types.h>
      ........
      ........
      #include <fcntl.h>
      int main()
      {
          int fd;
          umask(0026);
          fd = open("test.txt",O_RDWR | O_CREAT,0666);
          if(fd < 0)
              perror("open");
          return 0;
      }
      則生成的test.txt文件的權(quán)限是:666&(~026)結(jié)果是:-rw-r--r--.
      如果沒有umask(0026);這條語句,則生成的test.txt文件的權(quán)限是:666&(~022)結(jié)果是:-rw-r-----
      注:open函數(shù)的mode參數(shù)只有在創(chuàng)建文件時(shí)才有效。
         

      進(jìn)程從它的雙親進(jìn)程獲得它的對話過程和進(jìn)程組識別號。setsid()就是將進(jìn)程和它當(dāng)前的對話過程和進(jìn)程組分離開,并且把它設(shè)置成一個(gè)新的對話過程的領(lǐng)頭進(jìn)程。

      pid_t pid = fork();
      if (pid == 0) {
              ...
              int result = execl(path, "adb", "fork-server", "server", NULL);
      } else {
              // run a program in a new session
              setsid();//之前parent和child運(yùn)行在同一個(gè)session里,而且parent是session頭,所以,
              //所以作為session頭的parent如果exit結(jié)束執(zhí)行的話,那么會話session組中的所有進(jìn)程將都被殺死,
              //所以執(zhí)行setsid()之后,parent將重新獲得一個(gè)新的會話session組id,child將仍持有原有的會話session組,
              //這時(shí)parent退出之后,將不會影響到child了[luther.gliethttp].
      }

      會話是一個(gè)或多個(gè)進(jìn)程組的集合。進(jìn)程調(diào)用setsid函數(shù)建立一個(gè)新會話。
      如果調(diào)用此函數(shù)的進(jìn)程不是一個(gè)進(jìn)程組的組長,則此函數(shù)九會創(chuàng)建一個(gè)新會話,該進(jìn)餐變成會話的首進(jìn)程,然后該進(jìn)程成為一個(gè)新進(jìn)程組的組長進(jìn)程,該進(jìn)程沒有控制終端。因?yàn)闀捠走M(jìn)程是具有唯一進(jìn)程ID的單個(gè)進(jìn)程,所以可以將會話首進(jìn)程的進(jìn)程ID視為會話Id。

      sys.c中的創(chuàng)建一個(gè)會話的系統(tǒng)調(diào)用
      int sys_setsid(void)
      {
             ...
             current->leader = 1;
             current->session = current->pgrd = current->pid;
             current->tty = -1;    //表示該領(lǐng)頭進(jìn)程沒有控制終端。
             ...
      }

        本站是提供個(gè)人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點(diǎn)擊一鍵舉報(bào)。
        轉(zhuǎn)藏 分享 獻(xiàn)花(0

        0條評論

        發(fā)表

        請遵守用戶 評論公約

        類似文章 更多