Problem due to Fork Error

Hi,
I have developed a datastage job...which has many process running in parallel..but because of Fork Error my job is not working:(

Can any body help me out to solve this Fork error problem.:rolleyes:
My Os is SUNOS.
IS there any setting in Unix through admin where in if i set some paramter my process will get atomatically killed when specific duration has elapsed...

Thanks in Advance!!

there are two approaches to this.
1) set a timer in the child - which generates SIGALRM after specified 'n' units of time, register handler for that signal and in the handler, it should terminate itself

2) have a controller program which takes care of creating new process on need, monitoring them and if it lives more than the threshold trigger it with a signal and accordingly in the child register handler for that signal and it should terminate.

Both the methods are doable, and you will have more control with the second approach, as number of child to be spawned, time for which child should live everything can be configured in the invoker process

Thanks for your reply!:smiley:

Can you please tell me Second Method in detail..means which all commands i have to use(any sample):confused: ...I am quite new to unix.... :frowning:

Hello
While searching in this forum i have found the below link:

As per hell666 there is :
There's a limit to the number of fork() processes that can exist at any given point in time, and this limit is configurable. This threshold is there somewhere in the control panel (don't remember where), increase this limit.

So can anybody tell me what exactly i have to set??:confused:

Thanks in Advance!

Any Help on this???:frowning: :frowning:

Please do read the rules of the forum and donot bump up with questions if they are not promptly answered. :slight_smile:

Coming to the point,

monitor program would be a parent process which would fork() to create new child process, better to have some kind of count to control the child process creation ( MAX_CHILD_PROCESS_ALLOWED ), once fork is successful parent gets the child pid, store them in an array or any other data structure, check for the existence of the child by sending kill -0 ( to see if they exist ), or register any signal handlers in the child if any communication needs to be carried over between parent and child.

This is just a pointer and you will have many interesting challenges like daemon -izing, defunct process creation etc.

Give it a shot, post us if you are stuck up somewhere. :slight_smile:

As mentioned, this is sometimes due to a resource limitation, but you would be seeing a long list of "child" processes in your "ps" command if that were the case. Memory leaks can exhaust available RAM, which can also result in fork failures. The "second option" mentioned here is often done through use of IPC's such as semaphore's. We also use these for management of threads. Threads are more efficient because it does not cause a full process duplication. There are pthread.h management facilities available also, very cool to use and to have in your code.

The question gets down to whether one is multi-processing with the same code, or doing a fork/exec in order to spawn a completely separate process.

Does this help?

It's simple enough.

#define MAXC 25
pid_t do_child(char *cmd, char *args[]);

int main(void) {
int v = 0, x =0;
pid_t p_arrays[MAXC];

            while (v  <  MAXC) {p_arrays[v] = do_child(...); v++);
            while (x < (MAXC - 1)) {
                   if (waitpid(0,NULL,WNOHANG)) > 0) {x++;}
                   sleep(1);
             }
}
/*do_child with fork + execv is simple as is parsing and passing args to do_child in main*/

Sorry for the delay :frowning:
And thanks all for your replies.. :slight_smile:

I really helped..:smiley: