windows下,子进程占用父进程文件句柄问题

时间:2021-04-27 19:43:04   收藏:0   阅读:18

windows下,子进程占用父进程文件句柄问题

最近在项目中遇到一个问题,在windows下 用 _popen 方法创建管道,会导致子进程继承父进程文件句柄,导致父进程文件句柄被占用,从而导致日志文件重命名失败,最后设置可继承属性后解决了,记录下

转换句柄

  1. FILE * => int

      Gets the file descriptor associated with a stream.
      
      int _fileno( 
         FILE *stream 
      );
    
  2. int => HANDLE

    Returns operating-system file handle associated with existing low-level file descriptor.
    
    long _get_osfhandle( 
       int fd 
    
  3. HANDLE => int

    Associates a C run-time file descriptor with an existing operating-system file handle.
    
    int _open_osfhandle (
       intptr_t osfhandle,
          int flags 
    );
    

参考:

原文:https://www.cnblogs.com/beweirdo/p/14708884.html

评论(0
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!