0

I have client-server application. The server is in C. Server have this structure:

int main (... ) {
FILE * fp;
fp = fopen("serverLog.log","w");


//init variables
//bind server
//listen server on port
  while(1) {
  //some code
  //accept
  //some code
  int check = pthread_create(&thread, NULL, handle_client,&ctx);

  } 
 fclose(fp);
 return EXIT_SUCCSESS;
}

I run the server, and close the server using CTRL+C. What happens with filedescriptor fd? I suppose, that it stays open. If yes, what can I do with that? Thx

user1097772
  • 3,499
  • 15
  • 59
  • 95
  • 1
    Similar to this question: http://stackoverflow.com/questions/8175827/what-happens-if-i-dont-call-fclose-in-a-c-program - if you exit the program, its resources (memory, file descriptors) should be reclaimed by the OS. – wkl Mar 07 '12 at 20:53

1 Answers1

5

No, it will be closed by the operating system. When your process exits (whether cleanly or forcibly) the kernel will clean up all dangling handles.

Ben Russell
  • 1,413
  • 12
  • 15