-->

Previous | Table of Contents | Next

Page 757

ERRORS

EBADF fd is not a valid file descriptor open for writing.
EROFS, EINVAL fd is bound to a special file which does not support synchronization.
EIO An error occurred during synchronization.

BUGS

Currently (Linux 1.3.86) fdatasync is equivalent to fsync.

CONFORMS TO

POSIX.4

SEE ALSO

fsync(2), B.O. Gallmeister, POSIX.4, O'Reilly, pp. 220_223, 343.

Linux 1.3.86, 13 April 1996

flock

flock—Applies or removes an advisory lock on an open file

SYNOPSIS

#include <sys/file.h>

int flock(int fd,intoperation);

DESCRIPTION

Apply or remove an advisory lock on an open file. The file is specified by fd. Valid operations are given here:

LOCK_SH Shared lock. More than one process may hold a shared lock for a given file at a given time.
LOCK_EX Exclusive lock. Only one process may hold an exclusive lock for a given file at a given time.
LOCK_UN Unlock.
LOCK_NB Don't block when locking. May be specified (by oring) along with one of the other operations.
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.

RETURN VALUE

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

ERRORS

EWOULDBLOCK
The file is locked and the LOCK_NB flag was selected.

NOTES

Under Linux, flock is implemented as a call to fcntl. Please see fcntl(2) for more details on errors.

SEE ALSO

open(2), close(2), dup(2), execve(2), fcntl(2), fork(2)

Linux 0.99.11, 22 July 1993

Page 758

fork, vfork

fork, vfork—Creates a child process

SYNOPSIS


#include <unistd.h>

pid t fork(void);

pid t vfork(void);

DESCRIPTION

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.

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.

RETURN VALUE

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.

ERRORS

EAGAIN fork cannot allocate sufficient memory to copy the parent's page tables and allocate a task structure for the child.

BUGS

Under Linux, vfork is merely an alias for fork. fork never returns the error ENOMEM.

CONFORMS TO

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

SEE ALSO


clone(2), execve(2), wait(2)

Linux 1.2.9, 10 June 1995

fsync

fsync—Synchronizes a file's complete in-core state with that on disk

SYNOPSIS


#include <unistd.h>

int fsync(int fd);

DESCRIPTION

fsync copies all in-core parts of a file to disk.

In some applications, fdatasync is a more efficient alternative to fsync.

RETURN VALUE

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

Page 759

ERRORS

EBADF fd is not a valid file descriptor open for writing.
EROFS, EINVAL fd is bound to a special file that does not support synchronization.
EIO An error occurred during synchronization.

CONFORMS TO

POSIX.1b

SEE ALSO


bdflush(2), fdatasync(2), sync(2), update(8), sync(8)

Linux 1.3.85, 13 April 1996

getdents

getdents—Gets directory entries

SYNOPSIS


#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);

DESCRIPTION

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.

The dirent structure is declared as follows:


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) */

              }

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.

This call supersedes readdir(2).

RETURN VALUE

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.

ERRORS

EBADF Invalid file descriptor fd.
ENOTDIR File descriptor does not refer to a directory.

SEE ALSO


readdir(2), readdir(3)

Linux 1.3.6, 22 July 1995

Previous | Table of Contents | Next