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

📄 unx19.htm

📁 Linux Unix揭密.高质量电子书籍.对学习Linux有大帮助,欢迎下载学习.
💻 HTM
📖 第 1 页 / 共 5 页
字号:
immediately enter exit again, the shell will allow you to log out without warning. But, beware! The background processes are terminated immediately. If you don't want these background processes to be terminated, you must wait until they have completed 
before exiting. There is no way to log out while keeping the processes alive unless you plan ahead.

<BR></NOTE>

<HR ALIGN=CENTER>

<H4 ALIGN="CENTER">

<CENTER><A ID="I26" NAME="I26">

<FONT SIZE=3><B>Using </B><B><I>nohup</I></B>

<BR></FONT></A></CENTER></H4>

<P>Some of the commands you use may take so long to complete that you may not be able to (or want to) stay logged in until they complete. To change this behavior, you can use the nohup command. The word nohup simply precedes your normal command on the 
command line. Using nohup runs the command, ignoring certain signals. This allows you to log out, leaving the process running. As you log out, all your existing processes (those processes with your terminal as the controlling terminal) are sent the HUP 
signal. Since the process on which nohup is used ignores this signal, you can log out and the process will not terminate. If you have a nohup process in the background as you attempt to log out, your shell may warn you on your first exit command and 
require an immediate second exit in order to actually log out. (If yours is a shell that does job control, such as ksh or csh, see the section &quot;Job Control and Process Groups.&quot;)

<BR></P>

<HR ALIGN=CENTER>

<NOTE>

<IMG SRC="note.gif" WIDTH = 35 HEIGHT = 35><B>NOTE:</B>  There are several varieties of the nohup command. The SYSV nohup executable arranges for the command to ignore NOHUP and QUIT signals but does nothing regarding the TERM signal. If the output is 
going to standard out, it is redirected to the file nohup.out (or alternately to $HOME/nohup.out if you can't write to the first).

<BR>

<BR>The C shell has a built-in nohup command. It arranges for the command to ignore TERM signals. (In C shell, background commands automatically ignore the HUP signal.) It does not redirect output to the file nohup.out.

<BR>

<BR>Your system or shell may have a slight variation on the exact signals ignored and whether the nice value is changed when you use nohup.

<BR></NOTE>

<HR ALIGN=CENTER>

<H3 ALIGN="CENTER">

<CENTER><A ID="I27" NAME="I27">

<FONT SIZE=4><B>Prioritizing Processes</B>

<BR></FONT></A></CENTER></H3>

<P>Part of administering your processes is controlling how much CPU time they use and how important each process is relative to the others. UNIX supplies some fairly simple ways to monitor and control CPU usage of your process. This section describes how 
to use UNIX nice values to control your process CPU usage. By setting nice values for large jobs that aren't time critical, you can make your system more usable for other jobs that need to be done now.

<BR></P>

<H4 ALIGN="CENTER">

<CENTER><A ID="I28" NAME="I28">

<FONT SIZE=3><B>What Is a Priority?</B>

<BR></FONT></A></CENTER></H4>

<P>The UNIX kernel manages the scheduling of all processes on the system in an attempt to share the limited CPU resource fairly. Because UNIX has grown as a general purpose time-sharing system, the mechanism the scheduler uses tries to favor interactive 
processes over long-running, CPU-intensive processes so that users perceive good system response. UNIX always schedules the process that is ready to run (not waiting for I/O or an event) with the lowest numerical priority (that is, lower numbers are more 
important). If two processes with the same priority are ready, the scheduler will schedule the process that has been waiting the longest. If your process is CPU intensive, the kernel will automatically change your process priority based on how much CPU 
time your process is using. This gives preference to interactive applications that don't use lots of CPU time.

<BR></P>

<HR ALIGN=CENTER>

<NOTE>

<IMG SRC="note.gif" WIDTH = 35 HEIGHT = 35><B>NOTE:</B>  Low PRI means high priority. You may find it a bit confusing that lower numbers for priority mean &quot;higher&quot; priority. Try thinking of the scheduler starting out at priority zero and seeing 
if any processes at that priority are ready. If not, the scheduler tries priority 1, and so on.

<BR></NOTE>

<HR ALIGN=CENTER>

<P>To see how the UNIX scheduler works, look at the example in Table 19.1. In this example, three processes are each running long computations, and no other processes are trying to run. Each of the three processes will execute for a time slice and then let 

one of the other processes execute. Note that each process gets an equal share of the CPU. If you run an interactive process, such as a ps, while these three processes are running, you will get priority to run.

<BR></P>

<UL>

<LH><B>Table 19.1. Scheduling three CPU-intensive processes.</B>

<BR></LH></UL>

<TABLE BORDER>

<TR>

<TD>

<PRE><I>Process 1</I>

<BR></PRE>

<TD>

<PRE><I>Process 2</I>

<BR></PRE>

<TD>

<PRE><I>Process 3</I>

<BR></PRE>

<TR>

<TD>

<P>Running</P>

<TD>

<P>Waiting</P>

<TD>

<P>Waiting</P>

<TR>

<TD>

<P>Waiting</P>

<TD>

<P>Running</P>

<TD>

<P>Waiting</P>

<TR>

<TD>

<P>Waiting</P>

<TD>

<P>Waiting</P>

<TD>

<P>Running</P>

<TR>

<TD>

<P>Running</P>

<TD>

<P>Waiting</P>

<TD>

<P>Waiting</P>

<TR>

<TD>

<P>Waiting</P>

<TD>

<P>Running</P>

<TD>

<P>Waiting</P>

<TR>

<TD>

<P>Waiting</P>

<TD>

<P>Waiting</P>

<TD>

<P>Running</P></TABLE>

<H4 ALIGN="CENTER">

<CENTER><A ID="I29" NAME="I29">

<FONT SIZE=3><B>Being Nice</B>

<BR></FONT></A></CENTER></H4>

<P>One of the factors the kernel uses in determining a process priority is the nice value, a user-controlled value that indicates how &quot;nice&quot; you want a process to be to other processes. Traditionally, nice values range from 0 to 39 and default to 

20. Only root can lower a nice value. All other users can only make processes more nice than they were.

<BR></P>

<P>To see how the UNIX scheduler works with nice, look at the example in Table 19.2. In this example, three processes are each running long computations and no other processes are trying to run. This time, Process 1 was run with a nice value of 30. Each of 

the three processes will execute for a time slice and then let one of the other processes execute. However, in this case, Process 1 gets a smaller share of the CPU because the kernel uses the nice value in calculating the priority. Once again, if you run 
an interactive process, like a ps, while these three processes are running, you will get priority to run.

<BR></P>

<UL>

<LH><B>Table 19.2. Scheduling three CPU-intensive processes, one nicely.</B>

<BR></LH></UL>

<TABLE BORDER>

<TR>

<TD>

<PRE><I>Process 1</I>

<BR></PRE>

<TD>

<PRE><I>Process 2</I>

<BR></PRE>

<TD>

<PRE><I>Process 3, Nice Process</I>

<BR></PRE>

<TR>

<TD>

<P>Running</P>

<TD>

<P>Waiting</P>

<TD>

<P>Waiting</P>

<TR>

<TD>

<P>Waiting</P>

<TD>

<P>Running</P>

<TD>

<P>Waiting</P>

<TR>

<TD>

<P>Waiting</P>

<TD>

<P>Waiting</P>

<TD>

<P>Running</P>

<TR>

<TD>

<P>Running</P>

<TD>

<P>Waiting</P>

<TD>

<P>Waiting</P>

<TR>

<TD>

<P>Waiting</P>

<TD>

<P>Running</P>

<TD>

<P>Waiting</P>

<TR>

<TD>

<P>Running</P>

<TD>

<P>Waiting</P>

<TD>

<P>Waiting</P>

<TR>

<TD>

<P>Waiting</P>

<TD>

<P>Waiting</P>

<TD>

<P>Running</P>

<TR>

<TD>

<P>Waiting</P>

<TD>

<P>Running</P>

<TD>

<P>Waiting</P>

<TR>

<TD>

<P>Running</P>

<TD>

<P>Waiting</P>

<TD>

<P>Waiting</P>

<TR>

<TD>

<P>Waiting</P>

<TD>

<P>Running</P>

<TD>

<P>Waiting</P></TABLE>

<H4 ALIGN="CENTER">

<CENTER><A ID="I30" NAME="I30">

<FONT SIZE=3><B>Using </B><B><I>renice</I></B><B> on a Running Process</B>

<BR></FONT></A></CENTER></H4>

<P>BSD introduced the ability to change the nice value of other processes that are owned by you. The renice command gives you access to this capability. If you run a job and then decide it should be running with lower priority, you can use renice to do 
that.

<BR></P>

<HR ALIGN=CENTER>

<NOTE>

<IMG SRC="caution.gif" WIDTH = 37 HEIGHT = 35><B>CAUTION: </B> Not all systems have the renice command. Most systems based on BSD have it. Some systems, which are not based on BSD have added renice. The renice command on your system may take slightly 
different arguments than in the examples here. Check your system documentation to see if you have renice and what arguments it takes.

<BR></NOTE>

<HR ALIGN=CENTER>

⌨️ 快捷键说明

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