#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <assert.h>

main(){
int fds[2];
pipe(fds);
int pid = fork();

if(pid==0){
//system("ps -e -o pid,ppid,comm | grep uppg2");
sleep(4);
int test;
pid = fork();

if(pid==0){
test=close(0);assert(test==0);
test= close(1);assert(test==0);
test=dup(fds[1]);assert(test==0);
//test=close(0);assert(test==0);
test=close(fds[0]);assert(test==0);
test=close(fds[1]);assert(test==0);
sleep(1);
execlp("./g","./g",NULL);
fprintf(stderr,"execlp did not work\n");
//printf("Hej");
//system("ps -e -o pid,ppid,comm | grep uppg2");
sleep(2);
exit(1);
}
int childPid;
test=close(0);assert(test==0);
test=dup(fds[0]);assert(test==0);
test=close(fds[0]);assert(test==0);
test=close(fds[1]);assert(test==0);
read(0,&childPid,sizeof(int));
write(1,&childPid,sizeof(int));
printf("hej");
printf("this is the child pid %d",&childPid);
wait(0);

}
//system("ps -e -o pid,ppid,comm | grep uppg2");
wait(0);
//system("ps -e -o pid,ppid,comm | grep uppg2");
return 0;
}
