Quote:
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
void main()
{
int i;
int n;
pid_t childpid;
for(i = 1; i < 4; ++i)
{
if((childpid = fork()) <= 0)
{
break;
}
}
fprintf(stderr, "This process %ld with parent %ld\n", (long)getpid(), (long)getppid());
}
|
Try it like this
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
void main()
{
int i;
int n;
pid_t childpid;
for(i = 1; i < 4; ++i)
{
if((childpid = fork()) <= 0)) /*note that i put a ) at the end of the statement*/
{
break;
}
}
fprintf(stderr, "This process %ld with parent %ld\n", (long)getpid(), (long)getppid());
}
Just remember if you have more than on "(" in a statement then you need to add 2 ))
at the end of it.