I am a university student and I am trying to get the fork command to work into the following program but for some reason when i compile it on windows it gives me this error warning: implicit declaration of function 'fork' [-Wimplicit-function-declaration] 32 | pid1=fork();
.
#include <stdio.h>
#include <unistd.h>
int main(){
int pid1,pid2,pid3,pid4,pid5;
pid1=fork();
if (pid1 == 0) pid2 = fork();
else
pid3=fork();
if (pid3!=0){
pid4=fork();
if (pid4!=0)
pid5=fork();
}
printf("this is my pid: %d",getpid());
return 0;
}
(I included the unists header file because my linux vm doesn’t run the code unless i include it, again no clue why since from what i know the fork command should be included in the stdio file)
The weird thing is that when I try to compile it into linux it works perfectly fine for some reason. So im guessing it has something to do with my compiler but I dont know what exactly so I hope somebody can help me figure this out.