📄 0757-0759.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="0754-0756.html">Previous</A> | <a href="../ewtoc.html">Table of Contents</A> | <a href="0760-0763.html">Next</A></CENTER></P>
<A NAME="PAGENUM-757"><P>Page 757</P></A>
<P><B>
ERRORS
</B></P>
<TABLE>
<TR><TD>
EBADF
</TD><TD>
fd is not a valid file descriptor open for writing.
</TD></TR><TR><TD>
EROFS, EINVAL
</TD><TD>
fd is bound to a special file which does not support synchronization.
</TD></TR><TR><TD>
EIO
</TD><TD>
An error occurred during synchronization.
</TD></TR></TABLE>
<P><B>
BUGS
</B></P>
<P>Currently (Linux 1.3.86) fdatasync is equivalent to
fsync.
</P>
<P><B>
CONFORMS TO
</B></P>
<P>POSIX.4
</P>
<P><B>
SEE ALSO
</B></P>
<P>fsync(2), B.O. Gallmeister, POSIX.4, O'Reilly, pp. 220_223, 343.
</P>
<P>Linux 1.3.86, 13 April 1996
</P>
<H3><A NAME="ch02_ 24">
flock
</A></H3>
<P>flock—Applies or removes an advisory lock on an open file
</P>
<P><B>
SYNOPSIS
</B></P>
<!-- CODE SNIP //-->
<PRE>#include <sys/file.h>
int flock(int fd,intoperation);
</PRE>
<!-- END CODE SNIP //-->
<P><B>
DESCRIPTION
</B></P>
<P>Apply or remove an advisory lock on an open file. The file is specified by
fd. Valid operations are given here:
</P>
<TABLE>
<TR><TD>
LOCK_SH
</TD><TD>
Shared lock. More than one process may hold a shared lock for a given file at a given time.
</TD></TR><TR><TD>
LOCK_EX
</TD><TD>
Exclusive lock. Only one process may hold an exclusive lock for a given file at a given time.
</TD></TR><TR><TD>
LOCK_UN
</TD><TD>
Unlock.
</TD></TR><TR><TD>
LOCK_NB
</TD><TD>
Don't block when locking. May be specified (by
oring) along with one of the other operations.
</TD></TR><TR><TD>
</TD><TD>
A single file may not have both shared and exclusive locks.
A file is locked (that is, the inode), not the file descriptor. So,
dup(2) and fork(2) do not create multiple instances
of a lock.
</TD></TR></TABLE>
<P><B>
RETURN VALUE
</B></P>
<P>On success, 0 is returned. On error, _1 is returned and
errno is set appropriately.
</P>
<P><B>
ERRORS
</B></P>
<TABLE>
EWOULDBLOCK
<TR><TD>
The file is locked and the LOCK_NB
flag was selected.
</TD></TR></TABLE>
<P><B>
NOTES
</B></P>
<P>Under Linux, flock is implemented as a call to
fcntl. Please see fcntl(2) for more details on errors.
</P>
<P><B>
SEE ALSO
</B></P>
<P>open(2), close(2), dup(2), execve(2), fcntl(2),
fork(2)
</P>
<P>Linux 0.99.11, 22 July 1993
</P>
<A NAME="PAGENUM-758"><P>Page 758</P></A>
<H3><A NAME="ch02_ 25">
fork, vfork
</A></H3>
<P>fork, vfork—Creates a child process
</P>
<P><B>
SYNOPSIS
</B></P>
<!-- CODE SNIP //-->
<PRE>
#include <unistd.h>
pid t fork(void);
pid t vfork(void);
</PRE>
<!-- END CODE SNIP //-->
<P><B>
DESCRIPTION
</B></P>
<P>fork creates a child process that differs from the parent process only in its PID and PPID, and in the fact that
resource utilizations are set to 0. File locks and pending signals are not inherited.
</P>
<P>Under Linux, fork is implemented using copy-on-write pages, so the only penalties incurred by
fork are the time and memory required to duplicate the parent's page tables and to create a unique task structure for the child.
</P>
<P><B>
RETURN VALUE
</B></P>
<P>On success, the PID of the child process is returned in the parent's thread of execution, and a
0 is returned in the child's thread of execution. On failure, a
_1 will be returned in the parent's context, no child process will be created, and
errno will be set appropriately.
</P>
<P><B>
ERRORS
</B></P>
<TABLE>
<TR><TD>
EAGAIN
</TD><TD>
fork cannot allocate sufficient memory to copy the parent's page tables and allocate a
task structure for the child.
</TD></TR></TABLE>
<P><B>
BUGS
</B></P>
<P>Under Linux, vfork is merely an alias for fork.
fork never returns the error ENOMEM.
</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>
clone(2), execve(2), wait(2)
</PRE>
<!-- END CODE SNIP //-->
<P>Linux 1.2.9, 10 June 1995
</P>
<H3><A NAME="ch02_ 26">
fsync
</A></H3>
<P>fsync—Synchronizes a file's complete in-core state with that on disk
</P>
<P><B>
SYNOPSIS
</B></P>
<!-- CODE SNIP //-->
<PRE>
#include <unistd.h>
int fsync(int fd);
</PRE>
<!-- END CODE SNIP //-->
<P><B>
DESCRIPTION
</B></P>
<P>fsync copies all in-core parts of a file to disk.
</P>
<P>In some applications, fdatasync is a more efficient alternative to
fsync.
</P>
<P><B>
RETURN VALUE
</B></P>
<P>On success, 0 is returned. On error, _1 is returned and
errno is set appropriately.
</P>
<A NAME="PAGENUM-759"><P>Page 759</P></A>
<P><B>
ERRORS
</B></P>
<TABLE>
<TR><TD>
EBADF
</TD><TD>
fd is not a valid file descriptor open for writing.
</TD></TR><TR><TD>
EROFS, EINVAL
</TD><TD>
fd is bound to a special file that does not support synchronization.
</TD></TR><TR><TD>
EIO
</TD><TD>
An error occurred during synchronization.
</TD></TR></TABLE>
<P><B>
CONFORMS TO
</B></P>
<P>POSIX.1b
</P>
<P><B>
SEE ALSO
</B></P>
<!-- CODE SNIP //-->
<PRE>
bdflush(2), fdatasync(2), sync(2), update(8), sync(8)
</PRE>
<!-- END CODE SNIP //-->
<P>Linux 1.3.85, 13 April 1996
</P>
<H3><A NAME="ch02_ 27">
getdents
</A></H3>
<P>getdents—Gets directory entries
</P>
<P><B>
SYNOPSIS
</B></P>
<!-- CODE //-->
<PRE>
#include <unistd.h>
#include <linux/dirent.h>
#include <linux/unistd.h>
syscall3(int, getdents, uint, fd, struct dirent *, dirp, uint, count);
int getdents(unsigned int fd, struct dirent *dirp, unsigned int count);
</PRE>
<!-- END CODE //-->
<P><B>
DESCRIPTION
</B></P>
<P>getdents reads several dirent structures from the directory pointed at by
fd into the memory area pointed to by dirp. The parameter
count is the size of the memory area.
</P>
<P>The dirent structure is declared as follows:
</P>
<!-- CODE //-->
<PRE>
struct dirent
{
long d_ino; /* inode number */
off_t d_off; /* offset to next dirent */
unsigned short d_reclen; /* length of this dirent */
char d_name [NAME_MAX+1]; /* file name (null-terminated) */
}
</PRE>
<!-- END CODE //-->
<P>d_ino is an inode number. d_off is the distance from the start of the directory to the start of the next
dirent. d_reclen is the size of this entire dirent.
d_name is a null-terminated filename.
</P>
<P>This call supersedes readdir(2).
</P>
<P><B>
RETURN VALUE
</B></P>
<P>On success, the number of bytes read is returned. On end of directory,
0 is returned. On error, _1 is returned and errno is
set appropriately.
</P>
<P><B>
ERRORS
</B></P>
<TABLE>
<TR><TD>
EBADF
</TD><TD>
Invalid file descriptor fd.
</TD></TR><TR><TD>
ENOTDIR
</TD><TD>
File descriptor does not refer to a directory.
</TD></TR></TABLE>
<P><B>
SEE ALSO
</B></P>
<!-- CODE SNIP //-->
<PRE>
readdir(2), readdir(3)
</PRE>
<!-- END CODE SNIP //-->
<P>Linux 1.3.6, 22 July 1995
</P>
<P><CENTER>
<a href="0754-0756.html">Previous</A> | <a href="../ewtoc.html">Table of Contents</A> | <a href="0760-0763.html">Next</A></CENTER></P>
</td>
</tr>
</table>
<!-- begin footer information -->
</body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -