• <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 閱讀(5555) 評論(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.


            色婷婷久久久SWAG精品| 久久水蜜桃亚洲av无码精品麻豆 | 国产精品成人久久久久久久| 久久久国产乱子伦精品作者| 91久久精品91久久性色| 99久久国产亚洲高清观看2024| 久久性精品| 99精品久久精品一区二区| 久久久久久久99精品免费观看| 一本综合久久国产二区| 久久青青草原综合伊人| 要久久爱在线免费观看| 国内精品久久久人妻中文字幕| 久久福利青草精品资源站| 2019久久久高清456| 久久久久四虎国产精品| 国产免费久久久久久无码| 欧美麻豆久久久久久中文| 无码国产69精品久久久久网站| 久久男人中文字幕资源站| 久久偷看各类wc女厕嘘嘘| 久久亚洲AV无码西西人体| 国内精品伊人久久久久AV影院| 亚洲精品无码久久久久AV麻豆| 国产精品久久久久久吹潮| 99久久综合国产精品免费| 精品国产一区二区三区久久蜜臀| 亚洲一区精品伊人久久伊人| 久久久久国产精品| 久久精品国产精品国产精品污| 久久久久久久精品妇女99| 无码八A片人妻少妇久久| 丰满少妇人妻久久久久久4| 国产精品久久久久9999| 99久久精品国内| 丰满少妇人妻久久久久久| 久久综合精品国产二区无码| 亚洲精品高清国产一线久久| 久久精品人妻中文系列| 日韩人妻无码精品久久久不卡| 国产成人无码精品久久久性色|