How can I execute an external commands in C/Linux without using system, popen, fork, exec?

前端 未结 1 1361
青春惊慌失措
青春惊慌失措 2021-01-20 01:28

I would like to know if there is any good way to execute an external command in Linux environment using C language without using system(), popen(), fork(), exec()?

T

1条回答
  •  野的像风
    2021-01-20 01:52

    You cannot do this. Linux create new process by sequential call to fork() and exec(). No other way of process creation exists.

    But fork() itself is quite efficient. It uses Copy-on-Write for child process, so fork() not copy memory until it is really needed. So, if you call exec() right after fork() your system won't eat too much memory.

    UPD. I lie to you saying about process creation. In fact, there is clone() call which fork() uses internally. This call provides more control over process creation, but it can be complicated to use. Read man 2 fork and man 2 clone for more information.

    0 讨论(0)
提交回复
热议问题