• <ins id="pjuwb"></ins>
    <blockquote id="pjuwb"><pre id="pjuwb"></pre></blockquote>
    <noscript id="pjuwb"></noscript>
          <sup id="pjuwb"><pre id="pjuwb"></pre></sup>
            <dd id="pjuwb"></dd>
            <abbr id="pjuwb"></abbr>

            Prayer

            在一般中尋求卓越
            posts - 1256, comments - 190, trackbacks - 0, articles - 0
              C++博客 :: 首頁 :: 新隨筆 :: 聯系 :: 聚合  :: 管理

            system返回值

            Posted on 2010-11-01 17:46 Prayer 閱讀(5547) 評論(0)  編輯 收藏 引用 所屬分類: C/C++LINUX/UNIX/AIX

              system(執行shell 命令)

              相關函數  fork,execve,waitpid,popen

              表頭文件  #include<stdlib.h>

              定義函數  int system(const char * string);

              函數說明  system()會調用fork()產生子進程,由子進程來調用/bin/sh-c string來執行參數string字符串所代表的命令,此命令執行完后隨即返回原調用的進程。在調用system()期間SIGCHLD 信號會被暫時擱置,SIGINT和SIGQUIT 信號則會被忽略。

              返回值  如果system()在調用/bin/sh時失敗則返回127,其他失敗原因返回-1。若參數string為空指針(NULL),則返回非零值。如果system()調用成功則最后會返回執行shell命令后的返回值,但是此返回值也有可能為system()調用/bin/sh失敗所返回的127,因此最好能再檢查errno 來確認執行成功。

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

              范例  #include<stdlib.h>

              main()

              {

              system(“ls -al /etc/passwd /etc/shadow”);

              }

              執行  -rw-r--r-- 1 root root 705 Sep 3 13 :52 /etc/passwd

              -r--------- 1 root root 572 Sep 2 15 :34 /etc/shadow


                   Upon successful completion, the system subroutine returns the exit status of the shell. The exit status of the shell
                   is returned in the same manner as a call to the wait or waitpid subroutine, using the structures in the sys/wait.h
                   file.

                   If the String parameter is a null pointer and a command processor is available, the system subroutine returns a
                   nonzero value. If the fork subroutine fails or if the exit status of the shell cannot be obtained, the system
                   subroutine returns a value of -1. If the exec l subroutine fails, the system subroutine returns a value of 127. In
                   all cases, the errno global variable is set to indicate the error.


            麻豆精品久久精品色综合| 亚洲AV日韩AV天堂久久| 色综合久久久久网| 国产成人无码精品久久久久免费 | 国产精品久久永久免费| 嫩草影院久久国产精品| 亚洲人成无码网站久久99热国产| 久久久久久久波多野结衣高潮| AV色综合久久天堂AV色综合在| 久久国产精品免费一区| 久久久女人与动物群交毛片| 亚洲嫩草影院久久精品| 性高湖久久久久久久久| 亚洲成色999久久网站| 亚洲精品国产字幕久久不卡| 国内精品欧美久久精品| 青青草原精品99久久精品66| 欧美精品丝袜久久久中文字幕| 久久精品人人槡人妻人人玩AV| 综合久久久久久中文字幕亚洲国产国产综合一区首 | 无码专区久久综合久中文字幕 | 久久影视综合亚洲| 国产精品久久一区二区三区 | 97r久久精品国产99国产精| 伊人久久亚洲综合影院| 久久国产乱子伦精品免费午夜| 久久AV高清无码| 久久精品国产清自在天天线| 日本亚洲色大成网站WWW久久| 国产亚州精品女人久久久久久| 久久精品毛片免费观看| 久久久久亚洲AV无码专区体验| 久久毛片一区二区| 模特私拍国产精品久久| 欧美日韩中文字幕久久久不卡| 精品无码人妻久久久久久| 伊人久久大香线焦综合四虎 | 热综合一本伊人久久精品| 狠狠人妻久久久久久综合蜜桃| 99久久精品无码一区二区毛片 | 日日狠狠久久偷偷色综合免费|