Will someone please explain to me why this call to select won't return?
#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
int localpipes[2];
const char * message = "ichyfoobar";
int len;
int wresult,rresult;
int cstatus;
char buffer[98];
fd_set mainset;
int n;
void main()
{
len = strlen(message);
printf("creating pipes\n");
if (pipe(localpipes) < 0)
{
printf("Error with the pipe function\n");
exit(1);
}
printf("creating forked process\n");
if (fork() == 0)
{
if ((wresult = write(localpipes[1],message,len)) < 1)
{
printf("Error with write\n");
exit(2);
}
exit(0);
}
wait(&cstatus);
FD_ZERO(&mainset);
FD_SET(localpipes[0],&mainset);
printf("Gets stuck next line\n");
n = select(1,&mainset,NULL,NULL,NULL);
printf("We won't see this\n");
printf("n : %d\n",n);
printf("Reading the data\n");
if ((rresult = read(localpipes[0],buffer,70)) < 1)
{
printf("Error with read\n");
exit(3);
}
printf("%s\n",buffer);
exit(0);
}
I've tried putting values into the last struct timeval parameter, but that
doesn't seem to make any difference. Thanks in advance.
-john