linux-c-programming.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Daemon fork()ing 4 process
@ 2002-07-16  0:00 xlp
  0 siblings, 0 replies; 2+ messages in thread
From: xlp @ 2002-07-16  0:00 UTC (permalink / raw)
  To: linux-c-programming

Hi, I am coding in C a daemon that has to keep 4 process running doing certain operations and when for exmaple, one finish, It fork()s another with other option and so on.
Seudocode:
-Daemon starts,
-It fork()s 4 processess
-It waits for ANY of the procrosses to exit().
-If a process exits, it check the return value, and it fork()s another one with other argument.

C code:
main(){
	//fork();, parent dies.
	//setsid(); 
	//chdir(workdir);
	//umask();
	while(1){
		// What do you suggest?
	}
}

thanks.
	


^ permalink raw reply	[flat|nested] 2+ messages in thread

* RE: Daemon fork()ing 4 process
@ 2002-07-16  6:59 Alvarez Alberto-AALVARB1
  0 siblings, 0 replies; 2+ messages in thread
From: Alvarez Alberto-AALVARB1 @ 2002-07-16  6:59 UTC (permalink / raw)
  To: xlp, linux-c-programming

Hi,
	?maybe something like this? (I've copied this from Solaris code, I think it'll do)

struct CHILD_INFO{
	int child;               /*child pid */
	int pipechild[2]; 	/*child pipe, just in case */
};

> main(){
> 	//fork();, parent dies.
> 	//setsid(); 
> 	//chdir(workdir);
> 	//umask();
> 	while(1){
> 		// What do you suggest?

		for(i=0;i<4;i++)
		{	
			/*se crean los hijos*/
			if ((arraychild[i].child=fork())<0)/*error */
			{
				exit(0);
			}
			if(arraychild[i].hijo==0)/*child*/
			{
				ChildCode(i);
			}
			else /*father*/
			{
				...
			}
		}
		sigaction(...) or signal(...); /* catch the SIGCLD, and call ChildDead */
> 	}
> }
> 

void ChildDead(int xx)
{
	int pid_died,ret_code;
        	
	pid_died=wait(&ret_code);

	/* Now, you have the pid, so check it against arraychild and you'll know who has died */
	/* ret_code has information relevant to the child exit code (man wait) */

	....
}


Regards,

Alberto Alvarez Besada

Tlf.:        +34 914002155
e-mail.:   aalvarb1@motorola.com
            


> -----Original Message-----
> From: xlp [mailto:xlp@emtel.net.co]
> Sent: martes, 16 de julio de 2002 2:01
> To: linux-c-programming@vger.kernel.org
> Subject: Daemon fork()ing 4 process
> 
> 
> Hi, I am coding in C a daemon that has to keep 4 process 
> running doing certain operations and when for exmaple, one 
> finish, It fork()s another with other option and so on.
> Seudocode:
> -Daemon starts,
> -It fork()s 4 processess
> -It waits for ANY of the procrosses to exit().
> -If a process exits, it check the return value, and it 
> fork()s another one with other argument.
> 
> C code:
> main(){
> 	//fork();, parent dies.
> 	//setsid(); 
> 	//chdir(workdir);
> 	//umask();
> 	while(1){
> 		// What do you suggest?
> 	}
> }
> 
> thanks.
> 	
> 
> -
> To unsubscribe from this list: send the line "unsubscribe 
> linux-c-programming" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2002-07-16  6:59 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2002-07-16  0:00 Daemon fork()ing 4 process xlp
  -- strict thread matches above, loose matches on Subject: below --
2002-07-16  6:59 Alvarez Alberto-AALVARB1

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).