<em id="0a85b"><option id="0a85b"></option></em>

<abbr id="0a85b"></abbr>

      <nobr id="0a85b"></nobr>
        <tr id="0a85b"></tr>
        9久久伊人精品综合,亚洲一区精品视频在线,成 人免费va视频,国产一区二区三区黄网,99国产精品永久免费视频,亚洲毛片多多影院,精品久久久无码人妻中文字幕,无码国产欧美一区二区三区不卡
        學習啦>學習電腦>操作系統>Linux教程>

        linux system函數

        時間: 佳洲1085 分享

          system()函數是Linux下的一個函數,那么它具體作用是干什么呢?下面由學習啦小編為大家整理了linux system()函數的相關知識,希望對大家有幫助!

          一,linux system()函數理解

          功能:system()函數調用“/bin/sh -c command”執行特定的命令,阻塞當前進程直到command命令執行完畢

          原型:

          int system(const char *command);

          返回值:

          如果無法啟動shell運行命令,system將返回127;出現不能執行system調用的其他錯誤時返回-1。如果system能夠順利執行,返回那個命令的退出碼。

          說明:

          man幫助:

          #include

          int system(const char *command);

          DESCRIPTION

          system() executes a command specified in command by calling /bin/sh -c

          command, and returns after the command has been completed. During exe-

          cution of the command, SIGCHLD will be blocked, and SIGINT and SIGQUIT

          will be ignored.

          RETURN VALUE

          The value returned is -1 on error (e.g. fork(2) failed), and the

          return status of the command otherwise. This latter return status is

          in the format specified in wait(2). Thus, the exit code of the command

          will be WEXITSTATUS(status). In case /bin/sh could not be executed,

          the exit status will be that of a command that does exit(127).

          If the value of command is NULL, system() returns non-zero if the shell

          is available, and zero if not.

          system() does not affect the wait status of any other children.

          二,linux system()函數原理

          system函數執行時,會調用fork、execve、waitpid等函數。

          linux版system函數的源碼:

          int system(const char * cmdstring)

          {

          pid_t pid;

          int status;

          if(cmdstring == NULL){

          return (1);

          }

          if((pid = fork())<0){

          status = -1;

          }

          else if(pid == 0){

          execl("/bin/sh", "sh", "-c", cmdstring, (char *)0);

          _exit(127); //子進程正常執行則不會執行此語句

          }

          else{

          while(waitpid(pid, &status, 0) < 0){

          if(errno != EINTER){

          status = -1;

          break;

          }

          }

          }

          return status;

          }

          三,linux system()函數說明

          system()會調用fork()產生子進程,由子進程來調用/bin/sh-c string來執行參數string字符串所代表的命令,此命>令執行完后隨即返回原調用的進程。

          在調用system()期間SIGCHLD 信號會被暫時擱置,SIGINT和SIGQUIT 信號則會被忽略。

          返回值

          =-1:出現錯誤

          =0:調用成功但是沒有出現子進程

          >0:成功退出的子進程的id

          如果system()在調用/bin/sh時失敗則返回127,其他失敗原因返回-1。若參數string為空指針(NULL),則返回非零值>。如果system()調用成功則最后會返回

          執行shell命令后的返回值,但是此返回值也有可能為 system()調用/bin/sh失敗所返回的127,因此最好能再檢查errno 來確認執行成功。

          附加說明

          在編寫具有SUID/SGID權限的程序時請勿使用system(),system()會繼承環境變量,通過環境變量可能會造成系統安全的問題。

          system函數對返回值的處理,涉及3個階段:

          階段1:創建子進程等準備工作。如果失敗,返回-1。

          階段2:調用/bin/sh拉起shell腳本,如果拉起失敗或者shell未正常執行結束(參見備注1),原因值被寫入到status的低8~15比特位中。system的man中只說明了會寫了127這個值,但實測發現還會寫126等值。

          階段3:如果shell腳本正常執行結束,將shell返回值填到status的低8~15比特位中。

        3582371 主站蜘蛛池模板: 日韩不卡免费视频| www国产成人免费观看视频| 在线精品国产中文字幕| 亚洲AⅤ波多系列中文字幕| 岛国精品一区二区三区| 91麻豆精品国产91久| 2020国产成人精品视频| 欧美人与动牲交A免费观看| 亚洲一区二区三区影院| 亚洲人成网站久久久综合| 91福利视频一区二区| 2020国产在线视精品在| 久久中文字幕国产精品| 亚洲欧美日韩精品久久| 久久国内精品一区二区三区| 大地资源高清免费观看| 天天摸夜夜摸夜夜狠狠添| 国产精品av免费观看| 亚洲av无码国产在丝袜线观看| 亚洲愉拍一区二区三区| 国产三级精品三级| 亚洲国产成人资源在线| 色吊丝二区三区中文字幕| 性欧美VIDEOFREE高清大喷水| 婷婷综合缴情亚洲狠狠| 国产精品国产自产拍高清| 无码人妻少妇久久中文字幕蜜桃| 蜜臀精品视频一区二区三区| 色综合热无码热国产| 一个色综合色综合色综合| www亚洲精品| 欧美日韩在线亚洲二区综二| 国产日韩另类综合11页| 91久久偷偷做嫩草影院免费看| 亚洲AV永久无码天堂网一线| 最新永久无码AV网址亚洲| 日韩女同在线二区三区| 亚洲中文字幕一区久久| 中文字幕亚洲制服在线看| 视频一区无码中出在线| 欧洲中文字幕一区二区|