2012-05-07 11 views
1

私はクライアントがサーバーにファイル操作を発行するクライアントサーバーを持っています。最初の読み取り/削除コマンドが発行されると、プログラムは完全に実行されます。しかし、私は2番目のコマンドの読み取り/削除を発行すると、終了コード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

サーバーはループしていません。 1つのメッセージを受信して​​パイプを閉じるので、2回目の書き込みが失敗し、SIGPIPEがクライアントに送信されます。

+0

ありがとうございます。出来た – user1368949

関連する問題