-->

Previous | Table of Contents | Next

Page 751

ENOTDIR A component of the path prefix is not a directory.
EACCES Search permission is denied on a component of the path prefix.
ELOOP path contains a circular reference (that is, via a symbolic link)

SEE ALSO


chdir(2)

Linux 1.1.46, 21 August 1994

clone

clone—Creates a child process

SYNOPSIS


#include <linux/sched.h>

#include <linux/unistd.h>



pid t clone(void *sp, unsigned long flags);

DESCRIPTION

clone is an alternate interface to fork, with more options. fork is equivalent to clone(0, SIGCLD|COPYVM).

If sp is nonzero, the child process uses sp as its initial stack pointer.

The low byte of flags contains the signal sent to the parent when the child dies. flags may also be bitwise ored with either or both of COPYVM and COPYFD.

If COPYVM is set, child pages are copy-on-write images of the parent pages. If COPYVM is not set, the child process shares the same pages as the parent, and both parent and child may write on the same data.

If COPYFD is set, the child's file descriptors are copies of the parent's file descriptors. If COPYFD is not set, the child's file descriptors are shared with the parent.

RETURN VALUE

On success, the PID of the child process is returned in the parent's thread of execution, and 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

ENOSYS clone will always return this error, unless your kernel was compiled with CLONE_ACTUALLY_WORKS_OK defined.
EAGAIN fork cannot allocate sufficient memory to copy the parent's page tables and allocate a task structure for the child.

BUGS

By default, CLONE_ACTUALLY_WORKS_OK is not defined.

There is no entry for clone in /lib/libc.so.4.5.26.

Comments in the kernel as of 1.1.46 indicate that it mishandles the case where COPYVM is not set.

SEE ALSO


fork(2)

Linux 1.2.9, 10 June 1995

Page 752

close

close—Closes a file descriptor

SYNOPSIS


#include <unistd.h>

int close(int fd);

DESCRIPTION

close closes a file descriptor so that it no longer refers to any file and may be reused. Any locks held on the file it was associated with, and owned by the process, are removed (regardless of the file descriptor that was used to obtain the lock).

If fd is the last copy of a particular file descriptor, the resources associated with it are freed; if the descriptor was the last reference to a file that has been removed using unlink, the file is deleted.

RETURN VALUE

close returns 0 on success, or _1 if an error occurred.

ERRORS

EBADF fd isn't a valid open file descriptor.

CONFORMS TO

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

NOTES

Not checking the return value of close is a common but nevertheless serious programming error. File system implementations that use techniques as write-behind to increase performance may lead to write(2) succeeding, although the data has not been written yet. The error status may be reported at a later write operation, but it is guaranteed to be reported on closing the file. Not checking the return value when closing the file may lead to silent loss of data. This can especially be observed with NFS and disk quotas.

SEE ALSO


open(2), fcntl(2), shutdown(2), unlink(2),

fclose(3)

14 April 1996

connect

connect—Initiates a connection on a socket

SYNOPSIS


#include <sys/types.h>

#include <sys/socket.h>

int connect(int sockfd, struct sockaddr *serv_addr,intaddrlen);

DESCRIPTION

The parameter sockfd is a socket. If it is of type SOCK_DGRAM, this call specifies the peer with which the socket is to be associated; this address is that to which datagrams are to be sent, and the only address from which datagrams are to be received. If the socket is of type SOCK_STREAM, this call attempts to make a connection to another socket. The other socket is

Page 753

specified by serv_addr, which is an address in the communications space of the socket. Each communications space interprets the serv_addr, parameter in its own way. Generally, stream sockets may successfully connect only once; datagram sockets may use connect multiple times to change their association. Datagram sockets may dissolve the association by connecting to an invalid address, such as a null address.

RETURN VALUE

If the connection or binding succeeds, 0 is returned. On error, _1 is returned and errno is set appropriately.

ERRORS

See the Linux kernel source code for details.

HISTORY

The connect function call first appeared in BSD 4.2.

SEE ALSO


accept(2), bind(2), listen(2), socket(2),

getsockname(2)

Linux 0.99.11, 23 July 1993

dup, dup2

dup, dup2—Duplicate a file descriptor

SYNOPSIS


#include <unistd.h>

int dup(int oldfd);

int dup2(int oldfd,intnewfd);

DESCRIPTION

dup and dup2 create a copy of the file descriptor oldfd.

The old and new descriptors can 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.

dup uses the lowest-numbered unused descriptor for the new descriptor.

dup2 makes newfd be the copy of oldfd, closing newfd first if necessary.

RETURN VALUE

dup and dup2 return the new descriptor, or _1 if an error occurred (in which case errno is set appropriately).

ERRORS

EBADF oldfd isn't an open file descriptor, or newfd is out of the allowed range for file descriptors.
EMFILE The process already has the maximum number of file descriptors open and tried to open a new one.

WARNING

The error returned by dup2 is different from that returned by fcntl(...,F_DUPFD,...) when newfd is out of range. On some systems dup2 also sometimes returns EINVAL like F_DUPFD.

Previous | Table of Contents | Next