This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Forking a Process


Hi,

in case I am wrong here to ask, please tell me where else to ask instead!
The glibc page did not offer a "help" mailing list; therefore I post here.
I HAVE READ the manual and many web pages but nevertheless got questions.

I code on a C interpreter project called "CYBOI": http://www.cybop.net
The CYBOI interpreter has one single signal loop and many allocated
resources, as well as some mutexes and several threads.
I'd simply like to start an external program from within CYBOI.
The manuals describe two possibilities:
1 "pthread_create" copying all threads into the new child process
2 "fork" copying only the main thread -- the one that called "fork"

Since I just want to run some external program like "ls", "xdosemu",
"kmail", ... (whatever), without having any control about it,
I chose to use the second possibility, namely "fork".
Now I have just one thread in the child process, but still all the
resources of the parent process (including signal loop?) duplicated.
(By the way, I have taken care that the threads of the parent process
do *not* allocate any resources that could not be freed in the child,
since there, the threads do not exist.)

Questions:

1 Do I have to deallocate all duplicated resources in the child process,
  right after the "fork" and before running an "exec"?
  (The new child process runs an external program that does not need them.)

2 Isn't there a simpler way of starting an external program?
  I cannot imagine that a desktop environment like KDE, for example,
  starts applications with "fork" which copies all resources every time.

Thanks a lot for any hints,
Christian

(Please also address to me, since I'm not in the list!)


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]