I'm trying to run the following C program:
/*
* Illustrates system call fork
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int
main (
int argc,
char *argv[]
)
{
int tC, tF;
pid_t pid;
tC = atoi (argv[1]);
tF = atoi (argv[2]);
fprintf (stdout, "Main : ");
fprintf (stdout, "PID=%d; My parent PID=%d\n",
getpid(), getppid());
pid = fork();
if (pid == 0){
// Child
sleep (tC);
fprintf(stdout, "Child : PIDreturned=%d ", pid);
fprintf (stdout, "PID=%d; My parent PID=%d\n",
getpid(), getppid());
} else {
// Father
sleep (tF);
fprintf(stdout, "Father: PIDreturned=%d ", pid);
fprintf (stdout, "PID=%d; My parent PID=%d\n",
getpid(), getppid());
}
return 0;
}
I'm able to compile the code, but when I try to run the executable file I get a "segmentation fault (core dump)" error message.
Can anyone tell me what is causing such issue and how to fix it?