For the program
#include<stdio.h>
#include<stdlib.h>
#include<errno.h>
#include<unistd.h>
#include<sys/types.h>
int main()
{
pid_t var1;
int retVal, retStat;
printf("Program Started. Process PID = %d\n", getpid());
var1 = fork();
if(var1 < 0)
{
perror("Fork failed\n");
return 0;
}
else if(var1 == 0)
{
printf("Child process with pid = %d is executing\n", getpid());
printf("The var1 value in %d PID process is %d, my parent is %d\n", getpid(), var1, getppid());
}
else
{
printf("Process with pid = %d is executing\n", getpid());
printf("The var1 value in %d PID process is %d\n", getpid(), var1);
// wait(NULL);
retVal = wait(&retStat);
printf("Return status of child process is %d\n", retStat / 256);
printf("Return value for wait is %d\n", retVal);
}
printf("Process with PID = %d completed\n", getpid());
return 3;
}
I get the following warning -
warning: implicit declaration of function ‘wait’ [-Wimplicit-function-declaration]
But the program still compiles and the wait function works correctly. I checked in the libraries that I included and there is no definition for wait in any of them. I know that the wait syscall is defined in sys/wait.h
. I just want to know how does this program work correctly even after no declaration for wait().