• <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++博客 :: 首頁 :: 新隨筆 :: 聯(lián)系 :: 聚合  :: 管理

            system返回值

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

              system(執(zhí)行shell 命令)

              相關(guān)函數(shù)  fork,execve,waitpid,popen

              表頭文件  #include<stdlib.h>

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

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

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

              附加說明  在編寫具有SUID/SGID權(quán)限的程序時(shí)請(qǐng)勿使用system(),system()會(huì)繼承環(huán)境變量,通過環(huán)境變量可能會(huì)造成系統(tǒng)安全的問題。

              范例  #include<stdlib.h>

              main()

              {

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

              }

              執(zhí)行  -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.


            青草久久久国产线免观| 国产综合久久久久久鬼色| 日本加勒比久久精品| 免费精品国产日韩热久久| 亚洲国产精品成人久久| 国内精品久久九九国产精品| 久久久久久极精品久久久| 久久伊人五月丁香狠狠色| 国产精品久久久久久搜索| 人妻系列无码专区久久五月天| 伊人精品久久久久7777| 久久久综合九色合综国产| 亚洲国产成人久久一区久久| 久久婷婷五月综合色奶水99啪| 久久精品国产福利国产琪琪| 久久久久久亚洲Av无码精品专口| 狠狠色丁香婷婷综合久久来来去 | 高清免费久久午夜精品| 久久WWW免费人成—看片| 国产精品美女久久久久| 亚洲欧美国产日韩综合久久| 麻豆精品久久久一区二区| 日日噜噜夜夜狠狠久久丁香五月| 青草久久久国产线免观| 久久精品无码一区二区三区免费 | 久久精品aⅴ无码中文字字幕不卡| 久久九九久精品国产免费直播| 俺来也俺去啦久久综合网| 久久久一本精品99久久精品66 | 国产精品免费看久久久| 色欲久久久天天天综合网| 午夜精品久久久久久影视777| 91精品国产高清久久久久久91| 久久亚洲AV成人出白浆无码国产| 超级碰碰碰碰97久久久久| 欧美日韩中文字幕久久久不卡 | 久久久久久久久66精品片| 久久久WWW成人免费毛片| 久久精品国产WWW456C0M| 久久久黄片| 伊人久久一区二区三区无码|