Hi all !
What I want?
- All child process must be in the same group of process. Parent is a leader of the group.
How to do this? I would be greatfull of some example of code, I read about setsid
but I can't even start...
My code so far:
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int main(int argc, char *argv[])
{
int i ;
pid_t pid;
int val;
char *endptr;
if(argc != 2)
{
fprintf(stderr,"Error \n");
exit(EXIT_FAILURE);
}
val = strtol(argv[1],&endptr, 0);
if(endptr == argv[1])
{
fprintf(stderr,"Bad number ! \n");
exit(EXIT_FAILURE);
}
// okej
if(setsid() == -1)
{
perror("setsid");
}
for(i = 0; i < val; i++)
{
pid = fork();
if(pid < 0)
{
perror("Fork");
}
else if(pid==0)
{
int ret;
/* Child process */
printf("child process");
ret = execl("program1","program1", "145",NULL); // I run my second program
if(ret == -1)
perror("Execl");
}
else{
wait(NULL);
}
}
}