01-20-06 07:50 AM
Hi,
I am using FIFO as IPC. Server creates a FIFO and opens it in read only
mode(RDONLY).
Client opens it in write only mode(WRONLY). In infinite loop, i am
sending data (using writev system call) from client, & server (reads
using readv system call)displays it. During execution, i am suspending
the server process (KILL -STOP <serverpid> ). After this, writev call
in client is still passing.
Questions:
1) After server is stopped, How is it still passing (writev call in
client side)?
As per my knowledge, writev should through some error message to
indicate that condition.
Please help me to understand that behavior.
Thanks in advance
Param
Program Used:
fifo_client.c
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/uio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <signal.h>
void sigpipe_handler(int signum)
{
write(STDOUT_FILENO,"sigpipe caught",strlen("sigpipe caught"));
}
int main(int argc,char *argv[])
{
int fd;
char *buf="Parameswaran";
struct iovec data;
data.iov_base=buf;
data.iov_len=12;
/* signal(SIGPIPE, sigpipe_handler); */
if((fd=open("./pfifo", O_WRONLY )) == -1)
{
perror("Error");
exit(1);
}
while(1)
{
if(writev(fd,&data,1) == 12)
{
printf("writev successful\n");
sleep(1);
}
else {
perror("Error");
exit(1);
}
}
exit(0);
}
----------------------
fifo_server.c
#include <sys/types.h>
#include <sys/stat.h>
#include <sys/uio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
int main(int argc,char *argv[])
{
void exit_handler(void);
int fd;
char *buf=(char *)malloc(12);
int i;
struct iovec data;
data.iov_base=buf;
data.iov_len=12;
/* register exit handler */
if(atexit(exit_handler) != 0 )
{
perror("register");
exit(1);
}
if(mkfifo("./pfifo",0644)<0)
{
perror("Error");
exit(1);
}
if((fd=open("./pfifo", O_RDONLY)) == -1)
{
perror("open");
exit(1);
}
i=0;
while(i=3)
{
if(read(fd,buf,12) == data.iov_len)
{
printf("Request: %s\n",buf);
sleep(3);
}
else {
perror("read");
exit(1);
}
i++;
}
exit(0);
}
void exit_handler(void)
{
unlink("./pfifo");
}
[ Post a follow-up to this message ]
|