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

📄 ch24_03.htm

📁 the unix power tools
💻 HTM
字号:
<HTML><!--Distributed by F --><HEAD><TITLE>[Chapter 24] 24.3 Unlinking Open Files Isn't a Good Idea </TITLE><METANAME="DC.title"CONTENT="UNIX Power Tools"><METANAME="DC.creator"CONTENT="Jerry Peek, Tim O'Reilly &amp; Mike Loukides"><METANAME="DC.publisher"CONTENT="O'Reilly &amp; Associates, Inc."><METANAME="DC.date"CONTENT="1998-08-04T21:41:28Z"><METANAME="DC.type"CONTENT="Text.Monograph"><METANAME="DC.format"CONTENT="text/html"SCHEME="MIME"><METANAME="DC.source"CONTENT="1-56592-260-3"SCHEME="ISBN"><METANAME="DC.language"CONTENT="en-US"><METANAME="generator"CONTENT="Jade 1.1/O'Reilly DocBook 3.0 to HTML 4.0"><LINKREV="made"HREF="mailto:online-books@oreilly.com"TITLE="Online Books Comments"><LINKREL="up"HREF="ch24_01.htm"TITLE="24. Other Ways to Get Disk Space"><LINKREL="prev"HREF="ch24_02.htm"TITLE="24.2 Save Space with Bit Bucket Log Files and Mailboxes"><LINKREL="next"HREF="ch24_04.htm"TITLE="24.4 Save Space with a Link "></HEAD><BODYBGCOLOR="#FFFFFF"TEXT="#000000"><DIVCLASS="htmlnav"><H1><IMGSRC="gifs/smbanner.gif"ALT="UNIX Power Tools"USEMAP="#srchmap"BORDER="0"></H1><MAPNAME="srchmap"><AREASHAPE="RECT"COORDS="0,0,466,58"HREF="index.htm"ALT="UNIX Power Tools"><AREASHAPE="RECT"COORDS="467,0,514,18"HREF="jobjects/fsearch.htm"ALT="Search this book"></MAP><TABLEWIDTH="515"BORDER="0"CELLSPACING="0"CELLPADDING="0"><TR><TDALIGN="LEFT"VALIGN="TOP"WIDTH="172"><ACLASS="SECT1"HREF="ch24_02.htm"TITLE="24.2 Save Space with Bit Bucket Log Files and Mailboxes"><IMGSRC="gifs/txtpreva.gif"SRC="gifs/txtpreva.gif"ALT="Previous: 24.2 Save Space with Bit Bucket Log Files and Mailboxes"BORDER="0"></A></TD><TDALIGN="CENTER"VALIGN="TOP"WIDTH="171"><B><FONTFACE="ARIEL,HELVETICA,HELV,SANSERIF"SIZE="-1">Chapter 24<BR>Other Ways to Get Disk Space</FONT></B></TD><TDALIGN="RIGHT"VALIGN="TOP"WIDTH="172"><ACLASS="SECT1"HREF="ch24_04.htm"TITLE="24.4 Save Space with a Link "><IMGSRC="gifs/txtnexta.gif"SRC="gifs/txtnexta.gif"ALT="Next: 24.4 Save Space with a Link "BORDER="0"></A></TD></TR></TABLE>&nbsp;<HRALIGN="LEFT"WIDTH="515"TITLE="footer"></DIV><DIVCLASS="SECT1"><H2CLASS="sect1"><ACLASS="title"NAME="UPT-ART-0371">24.3 Unlinking Open Files Isn't a Good Idea </A></H2><PCLASS="para">[Some programmers write programs that<SPANCLASS="link"> make temporary files, open them, then unlink (remove) each file before they're done reading it . (<ACLASS="linkend"HREF="ch45_10.htm"TITLE="Removing a File Once It's Opened&nbsp;- for Security and Easy Cleanup">45.10</A>)</SPAN><ACLASS="indexterm"NAME="AUTOID-26261"></A><ACLASS="indexterm"NAME="AUTOID-26264"></A><ACLASS="indexterm"NAME="AUTOID-26267"></A>This keeps other people from deleting, reading, or overwriting a file.Because the file is opened by a process, UNIX removes the file's directory entry(its link) but doesn't actually free the disk space until theprocess is done with the file.Here's why you shouldn't do that.(By the way, the point Chris makes about system administrators cleaning upfull filesystems by emptying open files is a good one.)-JP]</P><PCLASS="para">To give people another reason not to unlink open files (besidesthat it does, er, &quot;interesting&quot; things under<SPANCLASS="link">NFS (<ACLASS="linkend"HREF="ch01_33.htm"TITLE="UNIX Networking and Communications ">1.33</A>)</SPAN>),consider the following:</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">multi 1000 &lt;/usr/dict/words &gt;/tmp/file1</PRE></BLOCKQUOTE></P><PCLASS="para">(<EMCLASS="emphasis">multi</EM> is a program that makes <EMCLASS="emphasis">n</EM> copies of its input; here <EMCLASS="emphasis">n</EM>is 1000.)Now suppose<SPANCLASS="link"><EMCLASS="emphasis">/tmp</EM> (<ACLASS="linkend"HREF="ch21_02.htm"TITLE="A Better Place for Temporary Files: /tmp ">21.2</A>)</SPAN>runs out of space.You can:</P><PCLASS="para"><BLOCKQUOTECLASS="screen"><PRECLASS="screen">rm /tmp/file1           # oops, file didn't actually go awayps ax                   # find the &quot;multi&quot; processkill <CODECLASS="replaceable"><I>pid</I></CODE>                # get rid of it</PRE></BLOCKQUOTE></P><PCLASS="para">or you can:</P><PCLASS="para"><TABLECLASS="screen.co"BORDER="1"><TR><THVALIGN="TOP"><PRECLASS="calloutlist"><ACLASS="co"HREF="ch13_14.htm"TITLE="13.14 What Can You Do with an Empty File? ">/dev/null</A> </PRE></TH><TDVALIGN="TOP"><PRECLASS="screen">cp /dev/null /tmp/file1 # now have some time to fix things up</PRE></TD></TR></TABLE></P><PCLASS="para">Bending the example a bit, suppose that <EMCLASS="emphasis">/tmp</EM> runs out of file spaceand there are a bunch of unlinked but<SPANCLASS="link">open (<ACLASS="linkend"HREF="ch45_20.htm"TITLE="Overview: Open Files and File Descriptors ">45.20</A>)</SPAN>files.To get rid ofthe space these occupy, you must kill the processes holding themopen. However, if they are ordinary files, you can just trim themdown to zero bytes.</P><PCLASS="para">There is one good reason to unlink open temporary files:if anything goes wrong, the temporary files will vanish.There is no other way to guarantee this absolutely.You must balance this advantage against the disadvantages.</P><DIVCLASS="sect1info"><PCLASS="SECT1INFO">- <SPANCLASS="authorinitials">CT</SPAN> <SPANCLASS="bibliomisc">in <ACLASS="systemitem.newsgroup"HREF="news:net.unix-wizards">net.unix-wizards</A> on Usenet, 9 September 1985</SPAN></P></DIV></DIV><DIVCLASS="htmlnav"><P></P><HRALIGN="LEFT"WIDTH="515"TITLE="footer"><TABLEWIDTH="515"BORDER="0"CELLSPACING="0"CELLPADDING="0"><TR><TDALIGN="LEFT"VALIGN="TOP"WIDTH="172"><ACLASS="SECT1"HREF="ch24_02.htm"TITLE="24.2 Save Space with Bit Bucket Log Files and Mailboxes"><IMGSRC="gifs/txtpreva.gif"SRC="gifs/txtpreva.gif"ALT="Previous: 24.2 Save Space with Bit Bucket Log Files and Mailboxes"BORDER="0"></A></TD><TDALIGN="CENTER"VALIGN="TOP"WIDTH="171"><ACLASS="book"HREF="index.htm"TITLE="UNIX Power Tools"><IMGSRC="gifs/txthome.gif"SRC="gifs/txthome.gif"ALT="UNIX Power Tools"BORDER="0"></A></TD><TDALIGN="RIGHT"VALIGN="TOP"WIDTH="172"><ACLASS="SECT1"HREF="ch24_04.htm"TITLE="24.4 Save Space with a Link "><IMGSRC="gifs/txtnexta.gif"SRC="gifs/txtnexta.gif"ALT="Next: 24.4 Save Space with a Link "BORDER="0"></A></TD></TR><TR><TDALIGN="LEFT"VALIGN="TOP"WIDTH="172">24.2 Save Space with Bit Bucket Log Files and Mailboxes</TD><TDALIGN="CENTER"VALIGN="TOP"WIDTH="171"><ACLASS="index"HREF="index/idx_0.htm"TITLE="Book Index"><IMGSRC="gifs/index.gif"SRC="gifs/index.gif"ALT="Book Index"BORDER="0"></A></TD><TDALIGN="RIGHT"VALIGN="TOP"WIDTH="172">24.4 Save Space with a Link </TD></TR></TABLE><HRALIGN="LEFT"WIDTH="515"TITLE="footer"><IMGSRC="gifs/smnavbar.gif"SRC="gifs/smnavbar.gif"USEMAP="#map"BORDER="0"ALT="The UNIX CD Bookshelf Navigation"><MAPNAME="map"><AREASHAPE="RECT"COORDS="0,0,73,21"HREF="../index.htm"ALT="The UNIX CD Bookshelf"><AREASHAPE="RECT"COORDS="74,0,163,21"HREF="index.htm"ALT="UNIX Power Tools"><AREASHAPE="RECT"COORDS="164,0,257,21"HREF="../unixnut/index.htm"ALT="UNIX in a Nutshell"><AREASHAPE="RECT"COORDS="258,0,321,21"HREF="../vi/index.htm"ALT="Learning the vi Editor"><AREASHAPE="RECT"COORDS="322,0,378,21"HREF="../sedawk/index.htm"ALT="sed &amp; awk"><AREASHAPE="RECT"COORDS="379,0,438,21"HREF="../ksh/index.htm"ALT="Learning the Korn Shell"><AREASHAPE="RECT"COORDS="439,0,514,21"HREF="../lrnunix/index.htm"ALT="Learning the UNIX Operating System"></MAP></DIV></BODY></HTML>

⌨️ 快捷键说明

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