2
我用c-unix語言創建了一個多進程客戶端服務器。 與客戶端的每個連接均作爲子進程進行管理。 當發生錯誤時,我只需調用函數出口(EXIT_FAILURE),因爲我讀到此函數關閉所有打開的流。 問題是:我必須關閉客戶端套接字描述符還是關閉是自動的?套接字描述符是否由函數exit(退出代碼)關閉?
我的代碼的一個例子是:
while(1){
if((client_sock=accept(ds_sock,&client,&s_client))==-1){
printf("Accept error\n");
exit(EXIT_FAILURE);
}
if(fork()==0){ //child
if((close(ds_sock)==-1)){
printf("Closing error\n");
exit(EXIT_FAILURE);
}
if((read(client_sock,&up,sizeof(userpass)))==-1){
printf("Error read\n");
exit(EXIT_FAILURE); //Does this instruction close the client_sock too?
}