Home » U++ Library support » U++ Library : Other (not classified elsewhere) » fork() problem
fork() problem [message #18936] |
Sat, 01 November 2008 20:29 |
mdelfede
Messages: 1307 Registered: September 2007
|
Ultimate Contributor |
|
|
This (very simple) gui app :
GUI_APP_MAIN
{
int pid;
pid = fork();
if(pid > 0)
{
PromptOK("Process " + AsString(pid));
return;
}
else if (pid == 0)
{
PromptOK("Parent Process");
return;
}
else
{
PromptOK("ERROR");
return;
}
TestFork().Run();
}
Crashes (with memory leak msgbox) instead of forking into 2 processes.
Max
|
|
|
|
|
Re: fork() problem [message #18956 is a reply to message #18955] |
Sun, 02 November 2008 16:34 |
|
mirek
Messages: 13975 Registered: November 2005
|
Ultimate Member |
|
|
mdelfede wrote on Sun, 02 November 2008 09:52 |
luzr wrote on Sun, 02 November 2008 15:07 |
mdelfede wrote on Sat, 01 November 2008 15:29 | This (very simple) gui app :
GUI_APP_MAIN
{
int pid;
pid = fork();
if(pid > 0)
{
PromptOK("Process " + AsString(pid));
return;
}
else if (pid == 0)
{
PromptOK("Parent Process");
return;
}
else
{
PromptOK("ERROR");
return;
}
TestFork().Run();
}
Crashes (with memory leak msgbox) instead of forking into 2 processes.
Max
|
Eh, I wish I knew all details that can go bad when forking GUI process. Anyway, for starters, there is socket open to communicate with X11 server - wonder what happens to that
Mirek
|
Well, I would have been happy to fork and close the parent (that was what I needed...) but doesn't work either.
I guess the fork() must be done BEFORE the gui initialization.
The strange stuff is that SysExec() package USES the fork() and it works....
Max
|
Ehm, now this one is correct and I am wrong.
In fact, theide itself forks in SlaveProcess quite frequently.
Mirek
|
|
|
|
Re: fork() problem [message #18980 is a reply to message #18958] |
Sun, 02 November 2008 22:55 |
mdelfede
Messages: 1307 Registered: September 2007
|
Ultimate Contributor |
|
|
luzr wrote on Sun, 02 November 2008 16:37 | Anyway, what is DOES NOT do is GUI in forked process. That might be the cause of crash.
If I understand fork docs correctly, that pesky socket will be duplicated. That means you will have two processes communicating with X11 instead of one - but for X11, it will still be a single process.
I guess there could be the problem.
Mirek
|
Yep, I've read that fork() just shares the file handles with both processes... if you close child (what happens with exit() function...) also the parent handles get closed.
BTW, that's not the problem in my small test app, it does crash BEFORE, even if I take off the PromptOK stuffs.
Ciao
Max
|
|
|
Goto Forum:
Current Time: Thu Mar 28 14:21:07 CET 2024
Total time taken to generate the page: 0.01845 seconds
|