简体   繁体   中英

can i open multiple popen without closing file-descriptor?

Can i use same file descriptor, for multiple popen, without closing it, before calling next popen, in same function? will it any memory leakage of any runtime error for long run? eg

    fun()
    { FILE *fd  = popen (some_command, "r");
      fd = popen (another_command, "r");
      fd = popen (another_command, "r");
      ... and so on..
      fclose(fd);   //at the end of the program 
    } 

Don't do that. You're losing the FILE* that the previous popen call returned so you will not be able to pclose() those. So this creates resource leaks, memory will not be released, and you risk not ever terminating the processes that gets started.

Note too that you should call pclose() instead of fclose()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM