2012-05-07 3 views
1

클라이언트가 서버에 파일 작업을 실행하는 클라이언트 서버가 있습니다. 첫 번째 읽기/삭제 명령이 발행 될 때 프로그램이 완벽하게 실행됩니다. 하지만 두 번째 명령 읽기/삭제 명령을 내릴 때 종료 코드 141이 나옵니다. 이유를 SIGPIPE로 결정하지만 해결할 수 없습니다. 누군가가 나를 도울 수 있습니까?SIGPIPE에 대한 이유를 확인할 수 없습니다.

#include <stdio.h> 
#include <sys/types.h> 
#include <unistd.h> 
#include <errno.h> 
#include <stdlib.h> 
#include <sys/ipc.h> 
#include <sys/msg.h> 
#include <string.h> 
#include <sys/wait.h> 
#include <mqueue.h> 
#include <sys/stat.h> 
//#include <limits.h> 
#include "Functions.h" 

#define PIPE_BUF 50000 
#define MAXMESGDATA (PIPE_BUF -2*sizeof(long)) 
#define MESGHDRSIZE (sizeof(Message_buf) -MAXMESGDATA) 
#define MAX_SIZE 512 

pid_t serverPid; 
pid_t clientPid; 



void Server(int readfd,int writefd) 
{ 
Message_buf server_MessageBuf; 
int operationStatus = 0; 
char inputFileName[MAXMESGDATA]; 
char operationToBePerformed[MAXMESGDATA]; 
char messageOnPIPE[MAXMESGDATA]; 
ssize_t length; 
if((length=mesg_recv(readfd,&server_MessageBuf))==0) 
{ 
    printf("\n End of file while reading pathname"); 
} 
strcpy(messageOnPIPE,server_MessageBuf.messageText); 
printf("\n Server side Message on PIPE:%s \n ",messageOnPIPE); 
operationStatus=interpretCommand(messageOnPIPE,operationToBePerformed,inputFileName); 
if(strcasecmp(operationToBePerformed,"read")==0) 
{ 
    readFile(writefd,inputFileName); 
    //printf("\n Read %s ",inputFileName); 
} 
if(strcasecmp(operationToBePerformed,"delete")==0) 
{ 
    deleteFile(writefd,inputFileName); 
} 
} 


int main() 
{ 
int pipe1[2],pipe2[2]; 
pipe(pipe1); 
pipe(pipe2); 
//signal(SIGPIPE, SIG_IGN); 

pid_t pid; 
pid=fork(); 
serverPid=pid; 

if(pid==0) 
{ 
    /*Call Server*/ 
    close(pipe1[1]); 
    close(pipe2[0]); 
    Server(pipe1[0], pipe2[1]); 
} 
else 
{ 
    close(pipe1[0]); 
    close(pipe2[1]); 
    Client(pipe2[0],pipe1[1]);  
} 
return 0; 
} 

답변

2

서버가 반복적으로 실행되고 있지 않습니다. 하나의 메시지를 수신 한 다음 파이프를 닫음으로써 두 번째 쓰기가 실패하고 SIGPIPE가 클라이언트로 전송됩니다.

+0

감사합니다. 효과가있다. – user1368949

관련 문제