⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 0751-0753.html

📁 linux-unix130.linux.and.unix.ebooks130 linux and unix ebookslinuxLearning Linux - Collection of 12 E
💻 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="0747-0750.html">Previous</A> | <a href="../ewtoc.html">Table of Contents</A> | <a href="0754-0756.html">Next</A></CENTER></P>







<A NAME="PAGENUM-751"><P>Page 751</P></A>



<TABLE>



<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>

path contains a circular reference (that is, via a symbolic link)

</TD></TR></TABLE>



<P><B>

SEE ALSO

</B></P>



<!-- CODE SNIP //-->

<PRE>

chdir(2)

</PRE>

<!-- END CODE SNIP //-->



<P>Linux 1.1.46, 21 August 1994

</P>



<H3><A NAME="ch02_ 17">

clone

</A></H3>



<P>clone&#151;Creates a child process

</P>



<P><B>

SYNOPSIS

</B></P>



<!-- CODE SNIP //-->

<PRE>

#include &lt;linux/sched.h&gt;

#include &lt;linux/unistd.h&gt;



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

</PRE>

<!-- END CODE SNIP //-->





<P><B>

DESCRIPTION

</B></P>



<P>clone is an alternate interface to fork, with more options.

fork is equivalent to clone(0, SIGCLD|COPYVM).

</P>



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

</P>



<P>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.

</P>



<P>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.

</P>



<P>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.

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

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>

ENOSYS

</TD><TD>

clone will always return this error, unless your kernel was compiled

with CLONE_ACTUALLY_WORKS_OK defined.

</TD></TR><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>By default, CLONE_ACTUALLY_WORKS_OK is not defined.

</P>



<P>There is no entry for clone in

/lib/libc.so.4.5.26.

</P>



<P>Comments in the kernel as of 1.1.46 indicate that it mishandles the case where

COPYVM is not set.

</P>



<P><B>

SEE ALSO

</B></P>



<!-- CODE SNIP //-->

<PRE>

fork(2)

</PRE>

<!-- END CODE SNIP //-->



<P>Linux 1.2.9, 10 June 1995

</P>



<A NAME="PAGENUM-752"><P>Page 752</P></A>





<H3><A NAME="ch02_ 18">

close

</A></H3>



<P>close&#151;Closes a file descriptor

</P>



<P><B>

SYNOPSIS

</B></P>



<!-- CODE SNIP //-->

<PRE>

#include &lt;unistd.h&gt;

int close(int fd);

</PRE>

<!-- END CODE SNIP //-->



<P><B>

DESCRIPTION

</B></P>



<P>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).

</P>



<P>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.

</P>



<P><B>

RETURN VALUE

</B></P>



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

</P>



<P><B>

ERRORS

</B></P>



<TABLE>



<TR><TD>

EBADF

</TD><TD>

fd isn't a valid open file descriptor.

</TD></TR></TABLE>



<P><B>

CONFORMS TO

</B></P>



<P>SVID, AT&amp;T, POSIX, X/OPEN, BSD 4.3

</P>



<P><B>

NOTES

</B></P>



<P>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.

</P>



<P><B>

SEE ALSO

</B></P>



<!-- CODE SNIP //-->

<PRE>

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

fclose(3)

</PRE>

<!-- END CODE SNIP //-->



<P>14 April 1996

</P>



<H3><A NAME="ch02_ 19">

connect

</A></H3>



<P>connect&#151;Initiates a connection on a socket

</P>



<P><B>

SYNOPSIS

</B></P>



<!-- CODE SNIP //-->

<PRE>

#include &lt;sys/types.h&gt;

#include &lt;sys/socket.h&gt;

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

</PRE>

<!-- END CODE SNIP //-->



<P><B>

DESCRIPTION

</B></P>



<P>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

</P>



<A NAME="PAGENUM-753"><P>Page 753</P></A>





<P>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.

</P>



<P><B>

RETURN VALUE

</B></P>



<P>If the connection or binding succeeds, 0 is returned. On error,

_1 is returned and errno is set appropriately.

</P>



<P><B>

ERRORS

</B></P>



<P>See the Linux kernel source code for details.

</P>



<P><B>

HISTORY

</B></P>



<P>The connect function call first appeared in BSD 4.2.

</P>



<P><B>

SEE ALSO

</B></P>



<!-- CODE SNIP //-->

<PRE>

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

getsockname(2)

</PRE>

<!-- END CODE SNIP //-->



<P>Linux 0.99.11, 23 July 1993

</P>



<H3><A NAME="ch02_ 20">

dup, dup2

</A></H3>



<P>dup, dup2&#151;Duplicate a file descriptor

</P>



<P><B>

SYNOPSIS

</B></P>



<!-- CODE SNIP //-->

<PRE>

#include &lt;unistd.h&gt;

int dup(int oldfd);

int dup2(int oldfd,intnewfd);

</PRE>

<!-- END CODE SNIP //-->



<P><B>

DESCRIPTION

</B></P>



<P>dup and dup2 create a copy of the file descriptor

oldfd.

</P>



<P>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.

</P>



<P>The two descriptors do not share the close-on-exec flag, however.

</P>



<P>dup uses the lowest-numbered unused descriptor for the new descriptor.

</P>



<P>dup2 makes newfd be the copy of oldfd, closing

newfd first if necessary.

</P>



<P><B>

RETURN VALUE

</B></P>



<P>dup and dup2 return the new descriptor, or _1 if an error occurred (in which case

errno is set appropriately).

</P>



<P><B>

ERRORS

</B></P>



<TABLE>



<TR><TD>

EBADF

</TD><TD>

oldfd isn't an open file descriptor, or

newfd is out of the allowed range for file descriptors.

</TD></TR><TR><TD>

EMFILE

</TD><TD>

The process already has the maximum number of file descriptors open and tried to open

a new one.

</TD></TR></TABLE>



<P><B>

WARNING

</B></P>



<P>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.

</P>









<P><CENTER>

<a href="0747-0750.html">Previous</A> | <a href="../ewtoc.html">Table of Contents</A> | <a href="0754-0756.html">Next</A></CENTER></P>







</td>
</tr>
</table>

<!-- begin footer information -->







</body></html>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -