Just wondering how if it's possible to execute another program in a thread and send information to/get information from it. Essentially the s开发者_如何学Goame concept as with a child process and using pipes to communicate - however I don't want to use fork.
I can't seem to find whether it's possible to do this, any help would be appreciated.
Thanks
You cannot use the exec
family of functions to load another executable file within a thread; the exec
functions replace the entire process with the process started from the executable. Thus fork()
is necessary if you want your original process to keep running.
In theory you could replicate most of the behaviour of the exec
system call in userspace, and run an executable within a thread - but as the thread would share the open file table, signal handlers and so on with the rest of the process, it would likely destructively interfere with the main process. It would also be a lot of work.
If you're not using fork (directly or indirectly), then it's not really another process. Of course, you can communicate between threads within a process. That's essential to most multithreading.
精彩评论