从C,C在Linux的发行系统命令++ [英] Issuing system commands in Linux from C, C++

查看:106
本文介绍了从C,C在Linux的发行系统命令++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道,在DOS / Windows应用程序,可以发出系统中使用的台词从code命令:

I know that in a DOS/Windows application, you can issue system commands from code using lines like:

system("pause");

system("myProgram.exe");

... stdlib.h中。是否有一个类似的Linux命令,如果是这头文件我会找到它?

...from stdlib.h. Is there a similar Linux command, and if so which header file would I find it in?

此外,这被认为是不好的编程习惯?我正在考虑试图让使用 lsmod的命令加载籽粒模块的列表。这是一个好主意还是坏主意?我发现一些网站,似乎在查看系统调用(至少系统(暂停);)从负面的角度

Also, is this considered bad programming practice? I am considering trying to get a list of loaded kernal modules using the lsmod command. Is that a good idea or bad idea? I found some websites that seemed to view system calls (at least system("pause");) in a negative light.

推荐答案

这并不奇怪,命令仍然

system("whatever");

和头仍文件stdlib.h 。这头文件的名字的意思是标准库,这意味着它是上支持C每一个标准的平台。

and the header is still stdlib.h. That header file's name means "standard library", which means it's on every standard platform that supports C.

和肯定,称系统()往往是一个坏主意。有做事通常更有计划性的方式。

And yes, calling system() is often a bad idea. There are usually more programmatic ways of doing things.

如果您想了解 lsmod的的作品,你可以随时查找了它的源代码code,看看主要的系统调用,它使。然后使用这些调用自己。

If you want to see how lsmod works, you can always look-up its source code and see what the major system calls are that it makes. Then use those calls yourself.

一个快速谷歌搜索变成了此链接,这表明 lsmod的正在读的/ proc /模块

A quick Google search turns up this link, which indicates that lsmod is reading the contents of /proc/modules.

这篇关于从C,C在Linux的发行系统命令++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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