打印

C problem

C problem

"Each descriptor has its own set of file descriptor flags.The close-on-exec file descriptor flag for the new descriptor is always cleared by the dup function."
what's the close-on-exec file descriptor flag?What's the use of it?
Thanks!

TOP

close-on-exec 是文件描述符的执行时关闭的一个标志,一般用于fork后再调用一个exec。假设父进程先打开描述符fd,然后调用exec,创建子进程,此时子进程应该也有一个描述符fd,若父进程在调用fork前fd的close-on-exec=0,则在子进程中fd也是打开的;若父进程在调用fork前fd的close-on-exec=1,则子进程中fd应该是关闭的。另外当通过dup产生一个新的描述符时,该描述符的close-on-exec 总是为0

TOP

非常。。。感谢!!

TOP