Okay sorry about before it was crazy So I tried to do a simplier test.
Code:
#include <sys/types.h>
#include <unistd.h>
#include <stdio.h>
#include <stdlib.h>
typedef struct BUF
{
char* type;
char* level;
int hi;
}__attribute__ ((packed)) BUF;
int main(){
pid_t pida, parent ;
BUF* duh = malloc(sizeof(*duh));
int rv;
int commpipe[2]; /* This holds the fd for the input & output of the pipe */
/* Setup communication pipeline first */
if (pipe( commpipe ) ) {
fprintf(stderr,"Pipe error!\n");
exit(1);
}
parent = getpid() ; /* get parent of me, the parent */
printf("main parent = %08X\n", getpid() ) ;
/* Fork Child #1 from "main" and check for errors */
pida = fork() ;
if (pida == -1) {
fprintf(stderr,"Fork error 1. Exiting.\n"); /* something went wrong */
exit(1);
}
if (pida == 0 ) {
/* A zero PID indicates that this is the child process */
sleep(5);
read(commpipe[0], duh, sizeof(duh));
printf("%s pipe output %s\n",duh->type, duh->level);
exit(0);
}
else {
/* A positive (non-negative) PID indicates the parent process */
BUF* dang = malloc(sizeof(*dang));
dang->type = "blood";
dang->level = "hard";
write(commpipe[1], dang, sizeof(dang));
sleep(2);
printf("Hello\n");
sleep(2);
printf("Goodbye\n");
sleep(2);
printf("exit\n");
wait(&rv); /* Wait for child process to end */
fprintf(stderr,"Child exited with a %d value\n",rv);
}
return 0;
}
my output is
main parent = 000055D9
Hello
Goodbye
blood pipe output (null)
exit
Child exited with a 0 value
so basically the duh->level equals NULL even though i assigned it to be "hard" b4 the write? So I'm not really sure how pipes send data does it not do it like parts at a time?