• <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.


            久久久国产精华液| 99久久综合国产精品二区| 久久综合综合久久97色| 亚洲狠狠婷婷综合久久蜜芽| 久久婷婷五月综合色99啪ak| 精品久久久久久亚洲| 2020久久精品国产免费| 久久综合狠狠综合久久综合88| 久久亚洲AV无码精品色午夜 | 国产午夜精品久久久久九九电影| 久久久精品2019免费观看| 午夜精品久久久久久中宇| 久久亚洲美女精品国产精品| 午夜精品久久久久久99热| 国产午夜福利精品久久2021| 国产亚洲美女精品久久久久狼| 99久久99久久久精品齐齐| 成人久久精品一区二区三区| 热re99久久精品国产99热| 久久亚洲av无码精品浪潮| 久久人人爽人人爽人人片AV麻烦| 久久天天躁狠狠躁夜夜avapp| 亚洲va久久久噜噜噜久久| 91精品国产高清久久久久久io| 久久亚洲国产中v天仙www| 精品久久久无码中文字幕天天| 亚洲国产精品嫩草影院久久 | 久久精品亚洲乱码伦伦中文| 国产精品久久久久久久人人看| 亚洲AV无码久久精品成人| 日本久久久精品中文字幕| 香港aa三级久久三级老师2021国产三级精品三级在 | 日韩精品国产自在久久现线拍 | 一本色道久久88综合日韩精品 | 蜜臀av性久久久久蜜臀aⅴ| 久久99精品久久久久久| 天堂无码久久综合东京热| 国产麻豆精品久久一二三| 欧洲性大片xxxxx久久久| 69久久精品无码一区二区| 久久久久久精品久久久久|