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. IIS5与IIS6 应用程序生命周期和页生命周期

    在写这篇博客之前,知好多前辈已经写过,自己班门弄斧,主要是加深自己对细节的理解,另一方面希望对浏览此篇文章的读者一个新的认识.注定是一长篇.肯定有新的认识,图示都是原创. 此篇所有牵涉的细节,我会一一 ...

  2. 使用PHP获取网站Favicon的方法

    使用PHP获取网站Favicon的方法 Jan022014 作者:Jerry Bendy   发布:2014-01-02 23:18   分类:PHP   阅读:4,357 views   20条评论 ...

  3. php 使用GD库上传图片以及创建缩略图

    php 使用GD库上传图片以及创建缩略图   GD库是PHP进行图象操作一个很强大的库. 先在php.ini里增加一行引用:extension=php_gd2.dll 重启apache.做一个测试页 ...

  4. 4Web镇之旅:开始链接

    为了将网页发布到web上,需要一个全日工作的网络服务器,最好的方法是找到一家主机代理商. 域名是用来定位网站的第一无二的名字. 网页的最顶层目录就是根目录.在Web服务器中,因为根目录中的东西有可能在 ...

  5. Android Studio 快捷键使用

    最近开始全面转向Android Studio开发了,经常要去查快捷键,索性汇总下,自己方便查找 IDE 按键    说明 F1 帮助 Alt(Option)+F1 查找文件所在目录位置 Alt(Opt ...

  6. JVM内存配置

    JVM内存主要分为两个部分,分别是PermanentSapce和HeapSpace. PermantSpace主要负责存放加载的Class类级对象如class本身,method,field等反射对象, ...

  7. jframe去掉窗体

    jframe 去掉最大化 怎样去除JFrame上的三个按钮(最大化,最小化,关闭) myjframe.getRootPane().setWindowDecorationStyle(JRootPane. ...

  8. Jquery小例子:全选按钮、加事件、挂事件;parent()语法;slideToggle()语法;animate()语法;元素的淡入淡出效果:fadeIn() 、fadeOut()、fadeToggle() 、fadeTo();function(e):e包括事件源和时间数据;append() 方法

    function(e): 事件包括事件源和事件数据,事件源是指是谁触发的这个事件,谁就是事件源(div,按钮,span都可以是事件源),时间数据是指比如点击鼠标的事件中,事件数据就是指点击鼠标的左建或 ...

  9. iOS简单排序--字母排序、NSDictionary排序

    // 数组用系统方法compare做字母的简单排序 NSArray *oldArray = @[@"bac",@"bzd",@"azc",@ ...

  10. Solaris 10下Qt编译Oracle 10g驱动

    上回书讲到<Oracle 10g在Solaris 10中安装详解>,现在开始用Qt来编译下Oracle 10g驱动吧!这样就可以通过Qt程序联入Oracle数据库了! Oracle的环境变 ...