如何系统()正好在Linux工作? [英] How does system() exactly work in linux?

查看:76
本文介绍了如何系统()正好在Linux工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在阅读它的手册页,但还没有成功地搞清楚它是如何工作。在调用系统(),是一个派生新的子进程和外壳二进制执行exec() - ed在呢?这可能是一个愚蠢的猜测虽然。

I've been reading its man page but haven't yet been successful in figuring out how it works. On calling system(), is a new child process forked and the shell binary exec()-ed in it? That may be a stupid guess though.

推荐答案

是的,系统()主要是为了传递命令字符串叉子()和exec()SH -c。示例实现(从eglibc,最近从glibc的分支),可以发现<一个href=\"http://www.eglibc.org/cgi-bin/viewcvs.cgi/branches/eglibc-2%5F9/libc/sysdeps/posix/system.c?rev=7350&view=markup\">here.

Yes, system() is essentially a fork() and exec() "sh -c" for the passed command string. An example implementation (from eglibc, recently forked from glibc) can be found here.

这篇关于如何系统()正好在Linux工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆