i have a question that tells me to write the output of the following program :
cont = 0; int p[2];
void* f1() {
while(!cont){}
printf("%d ", close(p[0])); return NULL;
}
int main() {
pthread_t t1;
pipe(p);
pthread_create(&t1,NULL,f1,NULL);
fork();
printf("%d ", close(p[0]));
cont = 1;
pthread_join(t1,NULL);
return 0;
}
the answer is 2 options : either 0 -1 0 or 0 0 -1
i think the answer is 0 -1 0 -1 , since everything is duplicated using fork() this means that the parent will call close(p[0]) and print 0 and then its duplication of the thread will call close(p[0]) but print -1 , and the same happens with the child. so overall 0 -1 0 -1 , what did i do wrong ?