Chinaunix首页 | 论坛 | 博客
  • 博客访问: 15339929
  • 博文数量: 2005
  • 博客积分: 11986
  • 博客等级: 上将
  • 技术积分: 22535
  • 用 户 组: 普通用户
  • 注册时间: 2007-05-17 13:56
文章分类

全部博文(2005)

文章存档

2014年(2)

2013年(2)

2012年(16)

2011年(66)

2010年(368)

2009年(743)

2008年(491)

2007年(317)

分类: LINUX

2010-06-04 10:11:20

关于fcntl(fd, F_SETFD, FD_CLOEXEC)设置exec时close的属性

snd_ctl_hw_open
#define SNDRV_FILE_CONTROL    ALSA_DEVICE_DIRECTORY "controlC%i"
sprintf(filename, SNDRV_FILE_CONTROL, card); // 路径/dev/snd/controlC0
fd = snd_open_device(filename, fmode);
fcntl(fd, F_SETFD, FD_CLOEXEC); // 这里设置为FD_CLOEXEC表示当程序执行exec函数时本fd将被系统自动关闭,表示不传递给exec创建的新进程, 如果设置为fcntl(fd, F_SETFD, 0);那么本fd将保持打开状态复制到exec创建的新进程中[luther.gliethttp].
进入内核系统调用
sys_fcntl
do_fcntl
    case F_SETFD:
        err = 0;
        set_close_on_exec(fd, arg & FD_CLOEXEC);

void fastcall set_close_on_exec(unsigned int fd, int flag)
{
    struct files_struct *files = current->files;
    struct fdtable *fdt;
    spin_lock(&files->file_lock);
    fdt = files_fdtable(files);
    if (flag)
        FD_SET(fd, fdt->close_on_exec);
    else
        FD_CLR(fd, fdt->close_on_exec);
    spin_unlock(&files->file_lock);
}
下面是man fcntl看到的对FD_CLOEXEC解释

File descriptor flags
   The  following  commands manipulate the flags associated with a file descriptor.  Currently, only one such flag is
   defined: FD_CLOEXEC, the close-on-exec flag.  If the FD_CLOEXEC bit is 0, the file  descriptor  will  remain  open
   across an execve(2), otherwise it will be closed.

   F_GETFD (void)
          Read the file descriptor flags; arg is ignored.
   F_SETFD (long)
          Set the file descriptor flags to the value specified by arg.
阅读(8827) | 评论(1) | 转发(0) |
给主人留下些什么吧!~~

chinaunix网友2010-06-17 23:03:37

[url=http://www.my-cheapshoes.com/nike-air-max-2010-c-78.html]nike air max 2010[/url] [url=http://www.my-cheapshoes.com/mbt-chapa-shoe-womens-mbt-chapa-shoe-c-65_67.html]Womens MBT Chapa Shoe[/url] [url=http://www.my-cheapshoes.com/mbt-lami-shoe-c-74.html]MBT Lami Shoe[/url] [url=http://www.my-cheapshoes.com/kobe-shoes-c-79.html]kobe shoes[/url] [url=http://www.my-cheapshoes.com/]MBT Shoes[/url] [url=http://www.my-cheapshoes.com/]Discount MBT[/url] [url=http://www.my-cheapshoes.com/]MBT