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

📄 390-392.html

📁 linux-unix130.linux.and.unix.ebooks130 linux and unix ebookslinuxLearning Linux - Collection of 12 E
💻 HTML
字号:
<HTML>

<HEAD>

<TITLE>Special Edition Using Linux, Fourth Edition:Managing Multiple Processes</TITLE>

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

<!--TITLE=Special Edition Using Linux, Fourth Edition//-->

<!--AUTHOR=Jack Tackett//-->

<!--AUTHOR=Jr.//-->

<!--AUTHOR=Steve Burnett//-->

<!--PUBLISHER=Macmillan Computer Publishing//-->

<!--IMPRINT=Que//-->

<!--CHAPTER=19//-->

<!--PAGES=390-392//-->

<!--UNASSIGNED1//-->

<!--UNASSIGNED2//-->



<CENTER>

<TABLE BORDER>

<TR>

<TD><A HREF="388-390.html">Previous</A></TD>

<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>

<TD><A HREF="392-394.html">Next</A></TD>

</TR>

</TABLE>

</CENTER>

<P><BR></P>

<P>Notice the pipe between the <TT>sort</TT> and <TT>mail</TT> commands in the preceding example. The command field can contain pipes, semicolons, arrows, or anything else you can enter on a shell command line. At the specified date and time, <TT>cron</TT> runs the entire command field with a standard shell (<TT>bash</TT>).</P>

<P>To specify a sequence of values for one of the first four fields, use commas to separate the values. Suppose you have a program, <TT>chkquotes</TT>, that accesses a service that provides stock quotes and puts the quotes in a file. To get those quotes at 9 a.m., 11 a.m., 2 p.m., and 4 p.m. on Monday, Tuesday, and Thursday of every week&#151;and definitely on the 10th of March and September&#151;use the following entry:</P>

<!-- CODE SNIP //-->

<PRE>

* 09,11,14,16 10 03,09 01,02,04 chkquotes

</PRE>

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

<P>Put the command lines into a file by using <TT>vi</TT> or some other editor that allows you to save files as text files. Assume that you put your commands in a file named <TT>cronjobs</TT>. To use <TT>crontab</TT> to put the file where <TT>cron</TT> can find it, enter this command:</P>

<!-- CODE SNIP //-->

<PRE>

<B>crontab cronjobs</B>

</PRE>

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

<P>Each time you use <TT>crontab</TT> this way, it overwrites any crontab file you may have already launched.</P>

<P>The <TT>crontab</TT> command has three options:</P>

<DL>

<DD><B>&#149;</B>&nbsp;&nbsp;The <TT>-e</TT> option edits the contents of the current crontab file. (The <TT>-e</TT> option opens your file by using the <TT>ed</TT> editor or whatever editor is assigned to the <TT>EDITOR</TT> variable in your shell.)

<BLOCKQUOTE>

<P><FONT SIZE="-1"><HR>&#149; <B>See</B> &#147;Setting the Shell Environment,&#148; <B>p. 344</B><HR></FONT>

</BLOCKQUOTE>

<DD><B>&#149;</B>&nbsp;&nbsp;The <TT>-r</TT> option removes the current crontab file from the crontabs directory.

<DD><B>&#149;</B>&nbsp;&nbsp;The <TT>-l</TT> option lists the contents of the current crontab file.

</DL>

<P>In all these cases, <TT>crontab</TT> works with the crontab file that has your login name. If your login name is mcn, your crontab file is /usr/spool/cron/crontabs/mcn. The <TT>crontab</TT> command does this automatically.</P>

<P>The system administrator and users share responsibility for making sure that the system is used appropriately. When you schedule a process, be aware of the impact it may have on the total system. Linux allows you, as the system administrator, to grant access to the <TT>at</TT>, <TT>batch</TT>, and <TT>cron</TT> commands to all users, specific users, or no users (or to deny access to individual users).</P>

<BLOCKQUOTE>

<P><FONT SIZE="-1"><HR><B>TROUBLESHOOTING:&nbsp;&nbsp;</B><BR><B>The commands I put in my crontab file don&#146;t work.</B> The <TT>cron</TT> command runs your crontab entries by using the Bourne Again shell (<TT>bash</TT>). Your entries fail if you use shell features not supported by <TT>bash</TT>. For example, the Public Domain Korn shell (<TT>pdksh</TT>) allows you to use either a tilde (~) to represent a home directory or the <TT>alias</TT> command to designate aliases for certain commands.

<P><B>When I try to use the <TT>at</TT> command, I&#146;m told I don&#146;t have permission to use it.</B> You haven&#146;t added your login ID to the /etc/cron.d/at.allow file.</P>

<P><B>I tried to use the <TT>at now</TT> command to run a command immediately.</B> No matter how fast you type, <TT>at now</TT> always responds with the message <TT>ERROR: Too late</TT>. The best alternative is to use the <TT>batch</TT> command to run the command for you. You can, however, use <TT>at now &#43;5 min</TT> to run the command in five minutes. After you press &lt;Return&gt;, type quickly to enter your command before the five minutes expire.<HR></FONT>

</BLOCKQUOTE>

</P>

<H3><A NAME="Heading11"></A><FONT COLOR="#000077">Reporting On and Monitoring the Multitasking Environment</FONT></H3>

<P>You know that Linux is a multiuser, multitasking operating system. Because so many people can do so many things with the system at the same time, users find it useful to determine who&#146;s using the system and what processes are running, as well as to monitor processes.

</P>

<P>Knowing that others can keep track of the commands you enter is important. Most users can&#146;t access your files without your permission, but they can see the names of commands you enter. Also, you (as the system administrator) or someone else who has the root password can peruse all the files on the system.</P>

<P>Although you don&#146;t have to be paranoid about privacy on a Linux system, you should know that the system can be monitored by anyone who wants to take the time to do it. The information you can gain about what&#146;s going on in the system is more useful than just satisfying curiosity: By seeing what jobs are running, you can appropriately schedule your tasks. You can also see whether a process of yours is still active and whether it&#146;s behaving properly.</P>

<H4 ALIGN="LEFT"><A NAME="Heading12"></A><FONT COLOR="#000077">Finding Out Who&#146;s on the System with <I>who</I>

</FONT></H4>

<P>The purpose of the <TT>who</TT> command is to find out who&#146;s logged in to the system. The <TT>who</TT> command lists the login names, terminal lines, and login times of users now logged in.</P>

<P>The <TT>who</TT> command is useful in many situations. If you want to communicate with someone on the computer by using the <TT>write</TT> command, for example, you can find out whether that person is on the system by using <TT>who</TT>. You can also use <TT>who</TT> to see when certain users are logged in to the computer to keep track of their time spent on the system.</P>

<P><FONT SIZE="+1"><B>Using <I>who</I> to List Users Logged In to the System

</B></FONT></P>

<P>To see everyone who&#146;s now logged in to the system, enter <B><TT>who</TT></B>. You see a display similar to the following:</P>

<!-- CODE SNIP //-->

<PRE>

$ <B>who</B>

root       console    Dec 13 08:00

ernie      tty02      Dec 13 10:37

bkraft     tty03      Dec 13 11:02

jdurum     tty05      Dec 13 09:21

ernie      ttys7      Dec 11 18:49

$

</PRE>

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

<P>This listing shows that root, ernie, bkraft, and jdurum are now logged in. It shows that root logged in at 8 a.m., bkraft at 11:02, and jdurum at 9:21. You can also see that ernie is logged in to two terminals and that one login occurred at 6:49 p.m. (18:49) two days earlier (which may be some reason for concern, or it may just be ernie&#146;s usual work habits).

</P>

<P><FONT SIZE="+1"><B>Using Headers in User Listings</B></FONT></P>

<P>Several options are available with <TT>who</TT>, but this chapter describes how to use only two to monitor processes on the system:</P>

<CENTER>

<TABLE WIDTH="70%"><TR>

<TD WIDTH="10%" ALIGN="LEFT"><TT>-u</TT>

<TD WIDTH="90%" ALIGN="LEFT">Lists only users who are now logged in

<TR>

<TD><TT>-H</TT>

<TD>Displays headers above each column

</TABLE>

</CENTER>

<P><BR></P>

<CENTER>

<TABLE BORDER>

<TR>

<TD><A HREF="388-390.html">Previous</A></TD>

<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>

<TD><A HREF="392-394.html">Next</A></TD>

</TR>

</TABLE>

</CENTER>





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

<!-- begin footer information -->





</body></html>

⌨️ 快捷键说明

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