system - execute a shell command

#include <stdlib.h>

int system (const char *command);

描述

system() executes a command specified in command by calling /bin/sh -c command, and returns after the command has been completed. During excution of the comman, SIGCHLD will be bocked, and SIGINT and SIGQUIT will be ignored.

返回值

错误返回-1,成功返回命令的退出状态。退出状态格式由wait指定,因此,命令的退出码是WEXITSTATUS(status). In case /bin/sh could not be executed, the exit status will be that of a command that dose exit(127).

If the value of command is NULL, system() returns nonzero if the shell is available, and zero if not.

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

注意

As mentioned, system() ignores SIGINT and SIGQUIT. This may make programs that call it from a loop uniterruptible, unless they take care themselves to check the exit status of the childl. E.g.

  while(something) {

    int ret = system("foo");

    if(WIFSIGNALED(ret) && (WTERMSIG(ret) == SIGINT || WTERMSIG(ret) == SIGQUIT))

      break;

  }

It is possible for the shell command to return 127, so that code is not a sure indication that the execve call fialed.

system执行shell命令的更多相关文章

  1. C语言system()函数:执行shell命令

    头文件:#include <stdlib.h> 定义函数:int system(const char * string); 函数说明:system()会调用fork()产生子进程, 由子进 ...

  2. 在程序中执行shell命令

    在linux系统下的操作中我们会经常用到shell命令来进行,一开始学习进程的时候对于shell命令也进行了思考,认为shell命令就是一个进程的外壳,经过了后来的学习对于这一点也有了更多的认识. 用 ...

  3. python(6)-执行shell命令

    可以执行shell命令的相关模块和函数有: os.system os.spawn* os.popen*          --废弃 popen2.*           --废弃 commands.* ...

  4. Android执行shell命令

    一.方法 /** * 执行一个shell命令,并返回字符串值 * * @param cmd * 命令名称&参数组成的数组(例如:{"/system/bin/cat", &q ...

  5. loadrunner调用plink,远程linux执行shell命令

    loadrunner调用plink,远程linux执行shell命令   脚本: Action() {   char* cmd; cmd = lr_eval_string("C:\\\&qu ...

  6. python 执行shell命令

    1.os模块中的os.system()这个函数来执行shell命令 1 2 3 >>> os.system('ls') anaconda-ks.cfg  install.log  i ...

  7. python中执行shell命令的几个方法小结

    原文 http://www.jb51.net/article/55327.htm 最近有个需求就是页面上执行shell命令,第一想到的就是os.system, os.system('cat /proc ...

  8. python中执行shell命令行read结果

    +++++++++++++++++++++++++++++ python执行shell命令1 os.system 可以返回运行shell命令状态,同时会在终端输出运行结果 例如 ipython中运行如 ...

  9. mysq在命令行模式下执行shell命令

    mysql可以在命令行模式下执行shell命令 mysql> help For information about MySQL products and services, visit: htt ...

随机推荐

  1. app.config中的connectionstring

    <connectionStrings>    <add name="wz" connectionString="server=www.junjv.com ...

  2. dig理解DNS的解析过程 - 阿权的书房

    关于DNS的常识,可以阅读附录的一些参考资料.本文旨在尝试举例用dig命令理解这个过程,并非权威知识,仅供参考.测试域名为阿权的书房的域名 www.aslibra.com 和 www.163.com. ...

  3. 点击li标记中的<a>标记改变li背景图片怎样实现

    <div class="nav"><ul><li id="li1" class="dianji" onclic ...

  4. Apache Spark源码走读之18 -- 使用Intellij idea调试Spark源码

    欢迎转载,转载请注明出处,徽沪一郎. 概要 上篇博文讲述了如何通过修改源码来查看调用堆栈,尽管也很实用,但每修改一次都需要编译,花费的时间不少,效率不高,而且属于侵入性的修改,不优雅.本篇讲述如何使用 ...

  5. PHP 设计模式 笔记与总结(4)PHP 链式操作的实现

    PHP 链式操作的实现 $db->where()->limit()->order(); 在 Common 下创建 Database.php. 链式操作最核心的地方在于:在方法的最后 ...

  6. TP中不区分大小写__APP__和__URL__的注意事项

    控制器命名为 : AuthGroupAction.class.php 问题 : 在控制器跳转中.如果模板跳转时地址的大小写错了..就会报无法加载模块 报错 : 无法加载模块:Authgroup 解决办 ...

  7. 动态样式语言Less学习笔记

    介绍资料参见:http://www.bootcss.com/p/lesscss/ LESS 将 CSS 赋予了动态语言的特性,如 变量, 继承,运算, 函数. LESS 既可以在 客户端 上运行 (支 ...

  8. xinwajueji

    #include<stdio.h> int map[10][10]={0}; int step[30]={0}; int max=99999; int ans[99]={0};  int ...

  9. ubuntu如何开启root,如何启用Ubuntu中root帐号

    jingyan.baidu.com/article/495ba84116104238b20ede62.html ubuntu如何开启root,如何启用Ubuntu中root帐号 | 浏览:8344 | ...

  10. css文件内引用外部资源文件的相对路径

    1.default.css文件内容(位于css文件夹下): .ClassName .ClassName .ClassName .page-sidebar .sidebar-search .submit ...