📄 0754-0756.html
字号:
<HTML>
<HEAD>
<TITLE>Linux Complete Command Reference:System Calls:EarthWeb Inc.-</TITLE>
</HEAD>
<META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW">
<SCRIPT>
<!--
function displayWindow(url, width, height) {
var Win = window.open(url,"displayWindow",'width=' + width +
',height=' + height + ',resizable=1,scrollbars=yes');
}
//-->
</SCRIPT>
</HEAD>
-->
<!-- ISBN=0672311046 //-->
<!-- TITLE=Linux Complete Command Reference//-->
<!-- AUTHOR=Red Hat//-->
<!-- PUBLISHER=Macmillan Computer Publishing//-->
<!-- IMPRINT=Sams//-->
<!-- CHAPTER=02 //-->
<!-- PAGES=0737-0890 //-->
<!-- UNASSIGNED1 //-->
<!-- UNASSIGNED2 //-->
<P><CENTER>
<a href="0751-0753.html">Previous</A> | <a href="../ewtoc.html">Table of Contents</A> | <a href="0757-0759.html">Next</A></CENTER></P>
<A NAME="PAGENUM-754"><P>Page 754</P></A>
<P><B>
CONFORMS TO
</B></P>
<P>SVID, AT&T, POSIX, X/OPEN, BSD 4.3
</P>
<P><B>
SEE ALSO
</B></P>
<!-- CODE SNIP //-->
<PRE>
fcntl(2), open(2), close(2).
</PRE>
<!-- END CODE SNIP //-->
<P>Linux 1.1.46, 21 August 1994
</P>
<H3><A NAME="ch02_ 21">
execve
</A></H3>
<P>execve—Execute program
</P>
<P><B>
SYNOPSIS
</B></P>
<!-- CODE SNIP //-->
<PRE>
#include <unistd.h>
int execve (const char *filename, const char *argv [], const char *envp[]);
</PRE>
<!-- END CODE SNIP //-->
<P><B>
DESCRIPTION
</B></P>
<P>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].
</P>
<P>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.
</P>
<P>If the current program is being ptraced, a
SIGTRAP is sent to it after a successful execve().
</P>
<P><B>
RETURN VALUE
</B></P>
<P>On success, execve() does not return; on error
_1 is returned and errno is set appropriately.
</P>
<P><B>
ERRORS
</B></P>
<TABLE>
<TR><TD>
EACCES
</TD><TD>
The file is not a regular file.
</TD></TR><TR><TD>
EACCES
</TD><TD>
Execute permission is denied for the file.
</TD></TR><TR><TD>
EPERM
</TD><TD>
The file system is mounted noexec.
</TD></TR><TR><TD>
EPERM
</TD><TD>
The file system is mounted nosuid and the file has an SUID or SGID bit set.
</TD></TR><TR><TD>
E2BIG
</TD><TD>
The argument list is too big.
</TD></TR><TR><TD>
ENOEXEC
</TD><TD>
The magic number in the file is incorrect.
</TD></TR><TR><TD>
EFAULT
</TD><TD>
filename points outside your accessible address space.
</TD></TR><TR><TD>
ENAMETOOLONG
</TD><TD>
filename is too long.
</TD></TR><TR><TD>
ENOENT
</TD><TD>
The file does not exist.
</TD></TR><TR><TD>
ENOMEM
</TD><TD>
Insufficient kernel memory was available.
</TD></TR><TR><TD>
ENOTDIR
</TD><TD>
A component of the path prefix is not a directory.
</TD></TR><TR><TD>
EACCES
</TD><TD>
Search permission is denied on a component of the path prefix.
</TD></TR><TR><TD>
ELOOP
</TD><TD>
filename contains a circular reference (that is, via a symbolic
link).
</TD></TR></TABLE>
<P><B>
CONFORMS TO
</B></P>
<P>SVID, AT&T, POSIX, X/OPEN, BSD 4.3
</P>
<P><B>
NOTES
</B></P>
<P>SUID and SGID processes can not be ptrace()'d SUID or SGID.
</P>
<A NAME="PAGENUM-755"><P>Page 755</P></A>
<P>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.
</P>
<P><B>
SEE ALSO
</B></P>
<!-- CODE SNIP //-->
<PRE>
execl(3), fork(2)
</PRE>
<!-- END CODE SNIP //-->
<P>Linux 1.1.46, 21 August 1994
</P>
<H3><A NAME="ch02_ 22">
fcntl
</A></H3>
<P>fcntl—Manipulate file descriptor
</P>
<P><B>
SYNOPSIS
</B></P>
<!-- CODE SNIP //-->
<PRE>
#include <unistd.h>
#include <fcntl.h>
int fcntl(int fd,intcmd);
int fcntl(int fd,intcmd,longarg);
</PRE>
<!-- END CODE SNIP //-->
<P><B>
DESCRIPTION
</B></P>
<P>fcntl performs one of various miscellaneous operations on
fd. The operation in question is determined by cmd:
</P>
<TABLE>
<TR><TD>
F_DUPFD
</TD><TD>
Makes arg be a copy of fd, closing fd first if necessary.
</TD></TR><TR><TD>
</TD><TD>
The same functionality can be more easily achieved by using dup2(2).
</TD></TR><TR><TD>
</TD><TD>
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.
</TD></TR><TR><TD>
</TD><TD>
The two descriptors do not share the close-on-exec flag, however.
</TD></TR><TR><TD>
</TD><TD>
On success, the new descriptor is returned.
</TD></TR><TR><TD>
F_GETFD
</TD><TD>
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.
</TD></TR><TR><TD>
F_SETFD
</TD><TD>
Set the close-on-exec flag to the value specified by
arg (only the least significant bit is used).
</TD></TR><TR><TD>
F_GETFL
</TD><TD>
Read the descriptor's flags (all flags—as set by
open(2)—are returned).
</TD></TR><TR><TD>
F_SETFL
</TD><TD>
Set the descriptor's flags to the value specified by arg.
</TD></TR><TR><TD>
</TD><TD>
Only O_APPEND and O_NONBLOCK may be set.
</TD></TR><TR><TD>
</TD><TD>
The flags are shared between copies (made with dup and so on) of the same file descriptor.
</TD></TR><TR><TD>
</TD><TD>
The flags and their semantics are described in open(2).
</TD></TR><TR><TD>
F_GETLK, F_SETLK,
</TD><TD>
Manage discretionary file locks. The third argument
arg is a pointer to a struct flock
</TD></TR><TR><TD>
and F_SETLKW
</TD><TD>
(that may be overwritten by this call).
</TD></TR><TR><TD>
F_GETLK
</TD><TD>
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.
</TD></TR><TR><TD>
F_SETLK
</TD><TD>
The lock is set (when l type is
F_RDLCK or F_WRLCK) or cleared (when it is F_UNLCK).
</TD></TR><TR><TD>
</TD><TD>
If the lock is held by someone else, this call returns
-1 and sets errno to EACCES or EAGAIN.
</TD></TR><TR><TD>
F_SETLKW
</TD><TD>
Like F_SETLK, but instead of returning an error, we wait for the lock to be released.
</TD></TR><TR><TD>
F_GETOWN
</TD><TD>
Get the process ID (or process group) of the owner of a socket.
</TD></TR><TR><TD>
</TD><TD>
Process groups are returned as negative values.
</TD></TR><TR><TD>
F_SETOWN
</TD><TD>
Set the process or process group that owns a socket.
</TD></TR><TR><TD>
</TD><TD>
For these commands, ownership means receiving
SIGIO or SIG-URG signals.
</TD></TR><TR><TD>
</TD><TD>
Process groups are specified using negative values.
</TD></TR></TABLE>
<A NAME="PAGENUM-756"><P>Page 756</P></A>
<P><B>
RETURN VALUE
</B></P>
<P>The return value depends on the operation:
</P>
<TABLE>
<TR><TD>
F_DUPFD
</TD><TD>
The new descriptor.
</TD></TR><TR><TD>
F_GETFD
</TD><TD>
Value of flag.
</TD></TR><TR><TD>
F_GETFL
</TD><TD>
Value of flags.
</TD></TR><TR><TD>
F_GETOWN
</TD><TD>
Value of descriptor owner.
</TD></TR></TABLE>
<P>On error, _1 is returned and errno is set appropriately.
</P>
<P><B>
ERRORS
</B></P>
<TABLE>
<TR><TD>
EBADF
</TD><TD>
fd is not an open file descriptor.
</TD></TR><TR><TD>
EINVAL
</TD><TD>
For F_DUPFD, arg is negative or is greater than the maximum allowable value.
</TD></TR><TR><TD>
EMFILE
</TD><TD>
For F_DUPFD, the process already has the maximum number of file descriptors open.
</TD></TR></TABLE>
<P><B>
NOTES
</B></P>
<P>The errors returned by dup2 are different from those returned by
F_DUPFD.
</P>
<P><B>
CONFORMS TO
</B></P>
<P>SVID, AT&T, POSIX, X/OPEN, BSD 4.3
</P>
<P><B>
SEE ALSO
</B></P>
<!-- CODE SNIP //-->
<PRE>
dup2(2), open(2), socket(2).
</PRE>
<!-- END CODE SNIP //-->
<P>Linux, 26 September 1995
</P>
<H3><A NAME="ch02_ 23">
fdatasync
</A></H3>
<P>fdatasync—Synchronizes a file's in-core data with that on disk
</P>
<P><B>
SYNOPSIS
</B></P>
<!-- CODE SNIP //-->
<PRE>
#include <unistd.h>
#ifdef POSIX SYNCHRONIZED IO
int fdatasync(int fd);
#endif
</PRE>
<!-- END CODE SNIP //-->
<P><B>
DESCRIPTION
</B></P>
<P>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.
</P>
<P>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.
</P>
<P><B>
RETURN VALUE
</B></P>
<P>On success, 0 is returned. On error, _1 is returned and
errno is set appropriately.
</P>
<P><CENTER>
<a href="0751-0753.html">Previous</A> | <a href="../ewtoc.html">Table of Contents</A> | <a href="0757-0759.html">Next</A></CENTER></P>
</td>
</tr>
</table>
<!-- begin footer information -->
</body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -