-->

Previous | Table of Contents | Next

Page 754

CONFORMS TO

SVID, AT&T, POSIX, X/OPEN, BSD 4.3

SEE ALSO


fcntl(2), open(2), close(2).

Linux 1.1.46, 21 August 1994

execve

execve—Execute program

SYNOPSIS


#include <unistd.h>

int execve (const char *filename, const char *argv [], const char *envp[]);

DESCRIPTION

execve() executes the program pointed to by filename. filename must be either a binary executable or a shell script starting with a line in the format #! interpreter [arg].

execve() does not return on success, and the text, data, bss, and stack of the calling process are overwritten by that of the program loaded. The program invoked inherits the calling process's PID, and any open file descriptors that are not set to close on exec. Signals pending on the parent process are cleared.

If the current program is being ptraced, a SIGTRAP is sent to it after a successful execve().

RETURN VALUE

On success, execve() does not return; on error _1 is returned and errno is set appropriately.

ERRORS

EACCES The file is not a regular file.
EACCES Execute permission is denied for the file.
EPERM The file system is mounted noexec.
EPERM The file system is mounted nosuid and the file has an SUID or SGID bit set.
E2BIG The argument list is too big.
ENOEXEC The magic number in the file is incorrect.
EFAULT filename points outside your accessible address space.
ENAMETOOLONG filename is too long.
ENOENT The file does not exist.
ENOMEM Insufficient kernel memory was available.
ENOTDIR A component of the path prefix is not a directory.
EACCES Search permission is denied on a component of the path prefix.
ELOOP filename contains a circular reference (that is, via a symbolic link).

CONFORMS TO

SVID, AT&T, POSIX, X/OPEN, BSD 4.3

NOTES

SUID and SGID processes can not be ptrace()'d SUID or SGID.

Page 755

A maximum line length of 127 characters is allowed for the first line in a #! executable shell script. This may be circumvented by changing the max size of buf, in which case you will become bound by the 1024 byte size of a buffer, which is not easily worked around.

SEE ALSO


execl(3), fork(2)

Linux 1.1.46, 21 August 1994

fcntl

fcntl—Manipulate file descriptor

SYNOPSIS


#include <unistd.h>

#include <fcntl.h>

int fcntl(int fd,intcmd);

int fcntl(int fd,intcmd,longarg);

DESCRIPTION

fcntl performs one of various miscellaneous operations on fd. The operation in question is determined by cmd:

F_DUPFD Makes arg be a copy of fd, closing fd first if necessary.
The same functionality can be more easily achieved by using dup2(2).
The old and new descriptors may be used interchangeably. They share locks, file position pointers, and flags; for example, if the file position is modified by using lseek on one of the descriptors, the position is also changed for the other.
The two descriptors do not share the close-on-exec flag, however.
On success, the new descriptor is returned.
F_GETFD Read the close-on-exec flag. If the low-order bit is 0, the file will remain open across exec; otherwise, it will be closed.
F_SETFD Set the close-on-exec flag to the value specified by arg (only the least significant bit is used).
F_GETFL Read the descriptor's flags (all flags—as set by open(2)—are returned).
F_SETFL Set the descriptor's flags to the value specified by arg.
Only O_APPEND and O_NONBLOCK may be set.
The flags are shared between copies (made with dup and so on) of the same file descriptor.
The flags and their semantics are described in open(2).
F_GETLK, F_SETLK, Manage discretionary file locks. The third argument arg is a pointer to a struct flock
and F_SETLKW (that may be overwritten by this call).
F_GETLK Return the flock structure that prevents us from obtaining the lock, or set the l type field of the lock to F_UNLCK if there is no obstruction.
F_SETLK The lock is set (when l type is F_RDLCK or F_WRLCK) or cleared (when it is F_UNLCK).
If the lock is held by someone else, this call returns -1 and sets errno to EACCES or EAGAIN.
F_SETLKW Like F_SETLK, but instead of returning an error, we wait for the lock to be released.
F_GETOWN Get the process ID (or process group) of the owner of a socket.
Process groups are returned as negative values.
F_SETOWN Set the process or process group that owns a socket.
For these commands, ownership means receiving SIGIO or SIG-URG signals.
Process groups are specified using negative values.

Page 756

RETURN VALUE

The return value depends on the operation:

F_DUPFD The new descriptor.
F_GETFD Value of flag.
F_GETFL Value of flags.
F_GETOWN Value of descriptor owner.

On error, _1 is returned and errno is set appropriately.

ERRORS

EBADF fd is not an open file descriptor.
EINVAL For F_DUPFD, arg is negative or is greater than the maximum allowable value.
EMFILE For F_DUPFD, the process already has the maximum number of file descriptors open.

NOTES

The errors returned by dup2 are different from those returned by F_DUPFD.

CONFORMS TO

SVID, AT&T, POSIX, X/OPEN, BSD 4.3

SEE ALSO


dup2(2), open(2), socket(2).

Linux, 26 September 1995

fdatasync

fdatasync—Synchronizes a file's in-core data with that on disk

SYNOPSIS


#include <unistd.h>

#ifdef POSIX SYNCHRONIZED IO

int fdatasync(int fd);

#endif

DESCRIPTION

fdatasync flushes all data buffers of a file to disk (before the system call returns). It resembles fsync but is not required to update the metadata such as access time.

Applications that access databases or log files often write a tiny data fragment (for example, one line in a log file) and then call fsync immediately in order to ensure that the written data is physically stored on the hard disk. Unfortunately, fsync will always initiate two write operations: one for the newly written data and another one in order to update the modification time stored in the inode. If the modification time is not a part of the transaction concept fdatasync can be used to avoid unnecessary inode disk write operations.

RETURN VALUE

On success, 0 is returned. On error, _1 is returned and errno is set appropriately.

Previous | Table of Contents | Next