Thanx man that did the trick but I have a slight problem. There is a work around but it's not efficient.
Code:
if (fork() == 0)
{
if ((fd = open(fdump, O_CREAT | O_RDWR, 0660)) < 0)
fprintf (stderr,"ERROR(opening file): %s.\n", strerror(errno));
dup2(fd, STDOUT);
if ((execl("/usr/bin/top", "/usr/bin/top","-b", "-n","1", NULL)) < 0)
fprintf (stderr,"ERROR(execl): %s.\n", strerror(errno));
close(fd);
read(fd, tmpBUF, msgSZ); <--------------- I don't seem to be getting here at all.
printf("before piping: %s./n/n", tmpBUF);
close(pd[READ]); //close read end of the pipe
write(pd[WRITE], tmpBUF, strlen(tmpBUF));
//printf("Sent to Parent: %s.\n", );
close(pd[WRITE]); //close write end
close(fd);
exit(0);
I can't get the print out of the buffer before send the contents to the parent. In fact after that execl() command it exits prematurely to the parent.