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()?
The reason I cannot use these functions is that my main application has used up most of the system resources (i.e memory) in my embedded board. If I do a fork, the board won't be able to create a duplicate of my main application. From I read in a book, both system() and popen() actually using fork() underneath, so I cannot use them either.
The only idea I currently have is create a process before I run my main application and use IPC(pipe or socket) to let the new process know what external commands it needs to run with system() or popen() and return the results back to my application when it is done.
You cannot do this. Linux create new process by sequential call to
exec(). No other way of process creation exists.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!Donate Us With