Hello guys.
Can I write structure data to child pipe?
Usual examples are about writing char* or int type.
I tried to write structure. But it does not look work.
Will you check my code?
-----------------------------------------------------------------------
struct work_list {
int heavy_rate; //0 - 5 level
int work_owner; //thread id
} ;
int main(void)
{
int fd[2], nbytes, icount;
pid_t childpid;
work_list work_ll[5] = {
{3, 5}, {3, 3}, {3, 4}, {4, 1}, {4, 3}};
work_list *readbuffer;
pipe(fd);
if((childpid = fork()) == -1)
{
perror("fork");
}
if(childpid != 0)
{
close(fd[0]);
write(fd[1], work_ll, (sizeof(work_ll)+1));
}
else
{
close(fd[1]);
nbytes = read(fd[0], readbuffer, sizeof(readbuffer));
cout << "Received string: " << readbuffer[0].dirty_rate << " byte " << nbytes << endl;
}
}