I would like to start a new process from each of my child process and have them do addition of numbers passed as parameters through exec()
. Something like this. I just don't know how I can access the parameters in the new process.
code.c
#include <stdio.h>
#include <stdlib.h>
# include <unistd.h>
# include <sys/types.h>
# include <sys/stat.h>
# include <time.h>
# include <stdlib.h>
# include <dirent.h>
# include <stdio.h>
# include <string.h>
# include <getopt.h>
# include<stdbool.h>
# include <ctype.h>
# include<sys/wait.h>
# include<signal.h>
# include <sys/mman.h>
# include<sys/time.h>
void forking()
{ int a=4,b=5
for (int i=0;i<4;i++)
pid_t pID = fork();
if (pID == 0)
{
static char *argv[]={a,b,NULL};
execv("/EXEC.c",argv);
}
else
wait(pID);
}
void main(int argc, char **argv)
{
forking();
}
EXEC.c
#include <stdio.h>
#include <stdlib.h>
# include <stdio.h>
# include <string.h>
int main()
{
//Code to add a and b and print the sum
printf("%d",a+b);
}