UNIX Socket FAQ

A forum for questions and answers about network programming on Linux and all other Unix-like systems

You are not logged in.

  • Index
  • » C
  • » how to create 03 child using c language

#1 2012-01-25 10:18 PM

faouzi
Member
Registered: 2012-01-25
Posts: 1

how to create 03 child using c language

i want to create 03 child using the function fork ()
but how i konw the  first child and the second child because
the first child must send a signal  SIGUSR1 to his father
the second child must send a signal  SIGUSR2 to his father

finaly thank you

Offline

#2 2012-01-26 12:24 AM

i3839
Oddministrator
From: Amsterdam
Registered: 2003-06-07
Posts: 2,231

Re: how to create 03 child using c language

Just call fork() and check the return value to distinguish
between the parent and the child process. Something like:

int create_child(int signal)
{
	int pid;
	
	pid = fork();
	if (pid == 0){
		/* Child code here */
		kill(getppid(), signal);
		exit(0);
	} else if (pid < 0){
		perror("Fork failed")
		return 1;
	}
	/* Return to parent */
	return 0;
}

Offline

#3 2012-01-26 11:50 PM

fouzi
Guest

Re: how to create 03 child using c language

thank you so much

  • Index
  • » C
  • » how to create 03 child using c language

Board footer

Powered by FluxBB