How to make the child process not inherit the resources of the parent process

Source: Internet
Author: User

About fcntl (FD, f_setfd, fd_cloexec) setting the close attribute during Exec

Snd_ctl_hw_open
# Define sndrv_file_control alsa_device_directory "controlc % I"
Sprintf (filename, sndrv_file_control, card); // path/dev/snd/controlc0
FD = snd_open_device (filename, fmode );
Fcntl (FD,
F_setfd, fd_cloexec );//
If this parameter is set to fd_cloexec, it indicates that when the program executes the exec function, This FD will be automatically disabled by the system, indicating that it will not be passed to the new process created by Exec,
If it is set to fcntl (FD, f_setfd, 0), This FD will remain open and copied to the newly created process [Luther. gliethttp] created by Exec.
Go to kernel system call
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 );
}
The following is the description of fd_cloexec seen by man fcntl.

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
Stored SS 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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.