Issuing system commands in Linux from C, C++

前端 未结 4 783
自闭症患者
自闭症患者 2020-11-27 21:50

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

system(\"pause\");

or

s         


        
4条回答
  •  萌比男神i
    2020-11-27 22:51

    Not surprisingly, the command is still

    system("whatever");
    

    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.

    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.

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

提交回复
热议问题