lkml.org 
[lkml]   [2006]   [Jan]   [11]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
/
Date
From
SubjectOT: fork(): parent or child should run first?
Hello,

The following problem may be simple for you, so I hope someone can answer
here. We've got a complex software using child processes and a table
to keep data of them together, like this:

childs[n].pid=fork();

where "n" is an integer contains a free "slot" in the childs struct array.

I also handle SIGCHLD in the parent and signal handler searches the childs
array for the pid returned by waitpid(). However here is my problem. The
child process can be fast, ie exits before scheduler of the kernel give
chance the parent process to run, so storing pid into childs[n].pid in the
parent context is not done yet. Child may exit, than scheduler gives control
to the signal handler before doing the store of the pid (if child run for
more time, eg 10 seconds it works of course). So it's impossible to store
child pids and search by that information in eg the signal handler? It's
quite problematic, since the code uses blocking I/O a lot, so other
solutions (like searching in childs[] in the main program and not in signal
handler) would require to recode the whole project. The problem can be
avoided with having a fork() run the PARENT first, but I thing this is done
by the scheduler so it's a kernel issue. Also the problem that source should
be portable between Linux and Solaris ...

Sorry for disturbing the list with this kind of problem but I can't find
any solution elsewhere.

Thanks a lot,

--
- Gábor
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

\
 
 \ /
  Last update: 2006-01-11 13:40    [W:0.549 / U:0.024 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site