Spark修煉之道(基礎篇)——Linux大資料開發基礎:第七節:程式管理
本節主要內容
- 程式管理簡介
- 程式管理常用命令
- 計劃任務
1. 程式管理簡介
(1)程式概念
程式是作業系統中非常重要的一個概念,程式是程式的執行過程,相對於程式,程式是動態的,在linux系統中,它與使用者許可權相關,程式與程式並沒有一一對應,一個程式可能對應多個程式,例如:
<code class="hljs java has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;"><span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">//ps命令列出當前所有對應當前使用者的活動程式</span> xtwy<span class="hljs-annotation" style="color: rgb(155, 133, 157); box-sizing: border-box;">@ubuntu</span>:~$ ps PID TTY TIME CMD <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2087</span> pts/<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">00</span>:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">00</span>:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">00</span> bash <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2105</span> pts/<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">00</span>:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">00</span>:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">00</span> ps xtwy<span class="hljs-annotation" style="color: rgb(155, 133, 157); box-sizing: border-box;">@ubuntu</span>:~$ bash <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">//一個bash程式對應多個程式</span> xtwy<span class="hljs-annotation" style="color: rgb(155, 133, 157); box-sizing: border-box;">@ubuntu</span>:~$ ps PID TTY TIME CMD <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2087</span> pts/<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">00</span>:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">00</span>:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">00</span> bash <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2141</span> pts/<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">00</span>:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">00</span>:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">00</span> bash <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2156</span> pts/<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">00</span>:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">00</span>:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">00</span> ps </code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li><li style="box-sizing: border-box; padding: 0px 5px;">5</li><li style="box-sizing: border-box; padding: 0px 5px;">6</li><li style="box-sizing: border-box; padding: 0px 5px;">7</li><li style="box-sizing: border-box; padding: 0px 5px;">8</li><li style="box-sizing: border-box; padding: 0px 5px;">9</li><li style="box-sizing: border-box; padding: 0px 5px;">10</li><li style="box-sizing: border-box; padding: 0px 5px;">11</li><li style="box-sizing: border-box; padding: 0px 5px;">12</li><li style="box-sizing: border-box; padding: 0px 5px;">13</li></ul>
子程式與父程式:一個程式產生另外一個程式,產生的程式稱為子程式,生成另外一個程式的程式稱為父程式。
<code class="hljs java has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;"><span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">//ps -l顯示長格式程式資訊</span> <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">//其中PID表示程式ID,PPID表示其父程式ID</span> xtwy<span class="hljs-annotation" style="color: rgb(155, 133, 157); box-sizing: border-box;">@ubuntu</span>:~$ ps -l F S UID PID PPID C PRI NI ADDR SZ WCHAN TTY TIME CMD <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span> S <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1000</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2087</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2085</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">80</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span> - <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1443</span> wait pts/<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">00</span>:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">00</span>:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">00</span> bash <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span> S <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1000</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2141</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2087</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">80</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span> - <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1443</span> wait pts/<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">00</span>:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">00</span>:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">00</span> bash </code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li><li style="box-sizing: border-box; padding: 0px 5px;">5</li><li style="box-sizing: border-box; padding: 0px 5px;">6</li><li style="box-sizing: border-box; padding: 0px 5px;">7</li></ul>
(2)程式狀態
程式狀態總體來看主要包括三種,分別是就緒狀態、執行狀態、等待狀態,就緒狀態指的是程式除了CPU資源,其他執行資源都已獲得,當就就緒狀態的程式得到CPU資源時,則進入程式進入執行狀態,執行狀態的程式在時間片用完後會重新轉換成就緒狀態,如果在執行時程式遇到IO等阻塞操作,則程式會進入等待狀態,等待狀態的程式當阻塞操作完成後,程式將進入就緒狀態
上述三種程式狀態還可以進一步細化,如下圖:
(3)前臺程式與後臺程式
前臺程式指的是程式在執行時會將命令列阻塞,直到程式執行完畢;後臺程式指的是程式在執行時不會阻塞當前命令列,而是在系統後臺執行。
<code class="hljs avrasm has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;">//直接<span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">ping</span>,作為前臺程式執行 root@ubuntu:~<span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;"># ping www.baidu.com </span> <span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">PING</span> www<span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">.a</span><span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">.shifen</span><span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;">.com</span> (<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">115.239</span><span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">.211</span><span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">.112</span>) <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">56</span>(<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">84</span>) bytes of data. <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">64</span> bytes from <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">115.239</span><span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">.211</span><span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">.112</span>: icmp_seq=<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span> ttl=<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">128</span> time=<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">4.50</span> ms //加&符號表示作為後臺程式進行執行 root@ubuntu:~<span class="hljs-preprocessor" style="color: rgb(68, 68, 68); box-sizing: border-box;"># ping www.baidu.com -a &</span> [<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>] <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">13330</span> </code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li><li style="box-sizing: border-box; padding: 0px 5px;">5</li><li style="box-sizing: border-box; padding: 0px 5px;">6</li><li style="box-sizing: border-box; padding: 0px 5px;">7</li><li style="box-sizing: border-box; padding: 0px 5px;">8</li><li style="box-sizing: border-box; padding: 0px 5px;">9</li></ul>
2. 程式管理常用命令
(1) ps命令
ps 命令常用選項包括:
(1)a顯示所有使用者的程式
(2)u顯示使用者名稱和啟動時間
(3)x顯示所有程式,包括沒有控制終端的程式
(4)e顯示所有程式,包括沒有控制終端的程式,較x選項,資訊更為簡略
(5)l顯示程式詳細資訊,按長格式顯示
下面給出幾個演示:
(1)ps -au 顯示所有使用者程式,並給出使用者名稱和啟動時間等詳細資訊
(2) ps -aux 顯示所有使用者程式,包括沒有控制終端的程式,並給出使用者和和啟動埋單等詳細資訊
<code class="hljs avrasm has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;">輸出格式中對應欄位含義: <span class="hljs-label" style="box-sizing: border-box;">USER:</span> 程式所有者 <span class="hljs-label" style="box-sizing: border-box;">PID:</span> 程式號 %CPU: CPU佔用率 %MEM: 記憶體佔用率 VSZ:表示如果一個程式完全駐留在記憶體的話需要佔用多少記憶體空間<span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">;</span> RSS:指明瞭當前實際佔用了多少記憶體<span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">;</span> <span class="hljs-label" style="box-sizing: border-box;">TTY:</span> 終端的次要裝置號碼 (minor device number of tty) <span class="hljs-label" style="box-sizing: border-box;">STAT:</span> 該程式程的狀態,有以下值 <span class="hljs-label" style="box-sizing: border-box;">D:</span> 不可中斷的靜止 <span class="hljs-label" style="box-sizing: border-box;">R:</span> 正在執行中 <span class="hljs-label" style="box-sizing: border-box;">S:</span> 靜止狀態 <span class="hljs-label" style="box-sizing: border-box;">T:</span> 暫停執行 <span class="hljs-label" style="box-sizing: border-box;">Z:</span> 不存在但暫時無法消除 <span class="hljs-label" style="box-sizing: border-box;">W:</span> 沒有足夠的記憶體分頁可分配 <: 高優先序的程式 <span class="hljs-label" style="box-sizing: border-box;">N:</span> 低優先序的程式 <span class="hljs-label" style="box-sizing: border-box;">L:</span> 有記憶體分頁分配並鎖在記憶體內 <span class="hljs-label" style="box-sizing: border-box;">START:</span> 程式開始時間 <span class="hljs-label" style="box-sizing: border-box;">TIME:</span> 執行的時間 <span class="hljs-label" style="box-sizing: border-box;">COMMAND:</span>所執行的指令</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li><li style="box-sizing: border-box; padding: 0px 5px;">5</li><li style="box-sizing: border-box; padding: 0px 5px;">6</li><li style="box-sizing: border-box; padding: 0px 5px;">7</li><li style="box-sizing: border-box; padding: 0px 5px;">8</li><li style="box-sizing: border-box; padding: 0px 5px;">9</li><li style="box-sizing: border-box; padding: 0px 5px;">10</li><li style="box-sizing: border-box; padding: 0px 5px;">11</li><li style="box-sizing: border-box; padding: 0px 5px;">12</li><li style="box-sizing: border-box; padding: 0px 5px;">13</li><li style="box-sizing: border-box; padding: 0px 5px;">14</li><li style="box-sizing: border-box; padding: 0px 5px;">15</li><li style="box-sizing: border-box; padding: 0px 5px;">16</li><li style="box-sizing: border-box; padding: 0px 5px;">17</li><li style="box-sizing: border-box; padding: 0px 5px;">18</li><li style="box-sizing: border-box; padding: 0px 5px;">19</li><li style="box-sizing: border-box; padding: 0px 5px;">20</li><li style="box-sizing: border-box; padding: 0px 5px;">21</li></ul>
(3) ps -l 按長格式顯示程式詳細資訊
<code class="hljs mathematica has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;">輸出格式對應欄位含義: F 程式的標誌, S 程式的狀態, PID 程式的ID, PPID 程式的父程式ID, <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">C</span> 程式的CPU佔用率, PRI 程式的優先權, NI 程式的Nice值, ADDR 程式的地址空間, SZ 程式佔用記憶體的大小, WCHAN 程式當前是否在執行, TTY 程式所屬終端, Time 程式的執行時間, CMD 程式的命令.</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li><li style="box-sizing: border-box; padding: 0px 5px;">5</li><li style="box-sizing: border-box; padding: 0px 5px;">6</li><li style="box-sizing: border-box; padding: 0px 5px;">7</li><li style="box-sizing: border-box; padding: 0px 5px;">8</li><li style="box-sizing: border-box; padding: 0px 5px;">9</li><li style="box-sizing: border-box; padding: 0px 5px;">10</li><li style="box-sizing: border-box; padding: 0px 5px;">11</li><li style="box-sizing: border-box; padding: 0px 5px;">12</li><li style="box-sizing: border-box; padding: 0px 5px;">13</li><li style="box-sizing: border-box; padding: 0px 5px;">14</li></ul>
(2) kill 命令
有時候某個程式可能會長期佔用CPU資源或無法正常執行或超出執行時間等,此時可能希望人工干預直接將程式殺死,這時候kill命令可以派上用場。
(1)kill pid,關閉程式
有時間kill並不能保證一定會關閉某個程式,例如
此時可以採用強制關閉的方式
(2)kill -9 pid,強制關閉程式
下面給出了強制程式的演示
強制關閉程式後,終端強制退出
(3) renice 修改程式的優先順序
<code class="hljs livecodeserver has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;">root@ubuntu:/home/xtwy<span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;"># ps -l</span> F S UID PID PPID C PRI NI ADDR SZ WCHAN TTY TIME CMD <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">4</span> S <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">12331</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">12306</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">99</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">19</span> - <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1120</span> <span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">wait</span> pts/<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">00</span>:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">00</span>:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">00</span> su <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span> S <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">12340</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">12331</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">99</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">19</span> - <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1144</span> <span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">wait</span> pts/<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">00</span>:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">00</span>:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">00</span> bash <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">4</span> R <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">12368</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">12340</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">99</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">19</span> - <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">625</span> - pts/<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">00</span>:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">00</span>:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">00</span> ps<span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;"> //重新指定許可權</span> root@ubuntu:/home/xtwy<span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;"># renice -5 12340</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">12340</span>: old priority <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">19</span>, <span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">new</span> priority -<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">5</span><span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;"> //子程式的許可權隨父程式許可權改變而改變</span> root@ubuntu:/home/xtwy<span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;"># ps -l</span> F S UID PID PPID C PRI NI ADDR SZ WCHAN TTY TIME CMD <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">4</span> S <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">12331</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">12306</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">99</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">19</span> - <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1120</span> <span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">wait</span> pts/<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">00</span>:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">00</span>:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">00</span> su <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span> S <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">12340</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">12331</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">75</span> -<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">5</span> - <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1144</span> <span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">wait</span> pts/<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">00</span>:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">00</span>:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">00</span> bash <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">4</span> R <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">12373</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">12340</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">75</span> -<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">5</span> - <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">625</span> - pts/<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">00</span>:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">00</span>:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">00</span> ps </code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li><li style="box-sizing: border-box; padding: 0px 5px;">5</li><li style="box-sizing: border-box; padding: 0px 5px;">6</li><li style="box-sizing: border-box; padding: 0px 5px;">7</li><li style="box-sizing: border-box; padding: 0px 5px;">8</li><li style="box-sizing: border-box; padding: 0px 5px;">9</li><li style="box-sizing: border-box; padding: 0px 5px;">10</li><li style="box-sizing: border-box; padding: 0px 5px;">11</li><li style="box-sizing: border-box; padding: 0px 5px;">12</li><li style="box-sizing: border-box; padding: 0px 5px;">13</li><li style="box-sizing: border-box; padding: 0px 5px;">14</li><li style="box-sizing: border-box; padding: 0px 5px;">15</li></ul>
(4) 程式的前臺後臺切換
(1)ctr+c命令終止程式
ping baidu.com -a 命令將一直執行,終端被佔用,要終止程式,需要使用ctr+c命令終止當前程式執行
<code class="hljs livecodeserver has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;">root@ubuntu:/home/xtwy<span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;"># ping baidu.com -a </span> PING baidu.com (<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">180.149</span><span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">.132</span><span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">.47</span>) <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">56</span>(<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">84</span>) <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">bytes</span> <span class="hljs-operator" style="box-sizing: border-box;">of</span> data. ^C64 <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">bytes</span> <span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">from</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">180.149</span><span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">.132</span><span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">.47</span>: icmp_seq=<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span> ttl=<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">128</span> <span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">time</span>=<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">138</span> ms <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;">--- baidu.com ping statistics ---</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span> packets transmitted, <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span> received, <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>% packet loss, <span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">time</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0</span>ms rtt <span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">min</span>/<span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">avg</span>/<span class="hljs-built_in" style="color: rgb(102, 0, 102); box-sizing: border-box;">max</span>/mdev = <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">138.291</span>/<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">138.291</span>/<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">138.291</span>/<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">0.000</span> ms </code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li><li style="box-sizing: border-box; padding: 0px 5px;">5</li><li style="box-sizing: border-box; padding: 0px 5px;">6</li><li style="box-sizing: border-box; padding: 0px 5px;">7</li><li style="box-sizing: border-box; padding: 0px 5px;">8</li><li style="box-sizing: border-box; padding: 0px 5px;">9</li></ul>
(2)ctr+z命令掛起程式
<code class="hljs ruby has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;">root<span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">@ubuntu</span><span class="hljs-symbol" style="color: rgb(0, 102, 102); box-sizing: border-box;">:/home/xtwy</span><span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;"># ping baidu.com -a </span> <span class="hljs-constant" style="box-sizing: border-box;">PING</span> baidu.com (<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">180.149</span>.<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">132.47</span>) <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">56</span>(<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">84</span>) bytes of data. ^<span class="hljs-constant" style="box-sizing: border-box;">Z</span> [<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>]+ <span class="hljs-constant" style="box-sizing: border-box;">Stopped</span> ping baidu.com -a root<span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">@ubuntu</span><span class="hljs-symbol" style="color: rgb(0, 102, 102); box-sizing: border-box;">:/home/xtwy</span><span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;"># jobs</span> [<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>]+ <span class="hljs-constant" style="box-sizing: border-box;">Stopped</span> ping baidu.com -a </code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li><li style="box-sizing: border-box; padding: 0px 5px;">5</li><li style="box-sizing: border-box; padding: 0px 5px;">6</li><li style="box-sizing: border-box; padding: 0px 5px;">7</li></ul>
(3)fg命令將程式轉到前臺執行
<code class="hljs handlebars has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;"><span class="xml" style="box-sizing: border-box;"><span class="hljs-tag" style="color: rgb(0, 102, 102); box-sizing: border-box;"><span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">root</span>@<span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">ubuntu:</span>/<span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">home</span>/<span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">xtwy</span># <span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">fg</span> <span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">ping</span> <span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">baidu.com</span> <span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">-a</span> <span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">64</span> <span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">bytes</span> <span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">from</span> <span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">180.149.132.47:</span> <span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">icmp_seq</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">2</span> <span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">ttl</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">128</span> <span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">time</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">135</span> <span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">ms</span> <span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">64</span> <span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">bytes</span> <span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">from</span> <span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">180.149.132.47:</span> <span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">icmp_seq</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">3</span> <span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">ttl</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">128</span> <span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">time</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">139</span> <span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">ms</span> <span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">64</span> <span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">bytes</span> <span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">from</span> <span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">180.149.132.47:</span> <span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">icmp_seq</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">4</span> <span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">ttl</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">128</span> <span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">time</span>=<span class="hljs-value" style="box-sizing: border-box; color: rgb(0, 136, 0);">135</span> <span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">ms</span> ^<span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">Z</span> [<span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">1</span>]+ <span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">Stopped</span> <span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">ping</span> <span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">baidu.com</span> <span class="hljs-attribute" style="box-sizing: border-box; color: rgb(102, 0, 102);">-a</span> </span></span></code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li><li style="box-sizing: border-box; padding: 0px 5px;">5</li><li style="box-sizing: border-box; padding: 0px 5px;">6</li><li style="box-sizing: border-box; padding: 0px 5px;">7</li><li style="box-sizing: border-box; padding: 0px 5px;">8</li></ul>
(4) bg命令將程式轉到後臺執行
<code class="hljs ruby has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;">root<span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">@ubuntu</span><span class="hljs-symbol" style="color: rgb(0, 102, 102); box-sizing: border-box;">:/home/xtwy</span><span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;"># bg</span> [<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>]+ ping baidu.com -a & root<span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">@ubuntu</span><span class="hljs-symbol" style="color: rgb(0, 102, 102); box-sizing: border-box;">:/home/xtwy</span><span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;"># 64 bytes from 180.149.132.47: icmp_seq=5 ttl=128 time=134 ms</span> jobs64 bytes from <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">180.149</span>.<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">132.47</span><span class="hljs-symbol" style="color: rgb(0, 102, 102); box-sizing: border-box;">:</span> icmp_seq=<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">6</span> ttl=<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">128</span> time=<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">135</span> ms [<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>]+ <span class="hljs-constant" style="box-sizing: border-box;">Running</span> ping baidu.com -a & </code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li><li style="box-sizing: border-box; padding: 0px 5px;">5</li><li style="box-sizing: border-box; padding: 0px 5px;">6</li><li style="box-sizing: border-box; padding: 0px 5px;">7</li></ul>
(5)jobs命令檢視任務
<code class="hljs ruby has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;">root<span class="hljs-variable" style="color: rgb(102, 0, 102); box-sizing: border-box;">@ubuntu</span><span class="hljs-symbol" style="color: rgb(0, 102, 102); box-sizing: border-box;">:/home/xtwy</span><span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;"># jobs</span> [<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>]+ <span class="hljs-constant" style="box-sizing: border-box;">Running</span> ping baidu.com -a &</code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li></ul>
(5) top命令動態顯示程式資訊
top命令動態顯示程式資訊,可以對程式的CPU、記憶體使用情況進行動態監測
(6) pstree顯示程式樹
將程式間的關係以樹結構的形式展示
3. 計劃任務的設定
(1) at命令安排作業在某一時刻執行一次
at命令指定時間的方式
絕對計時方法:
hh:mm MM/DD/YY
相對計時方法:
now+n minutes
mow+n hours
now+n days
<code class="hljs livecodeserver has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;">//<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">5</span>分鐘後執行echo <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"hello"</span> > /home/xtwy/hellohello.txt xtwy@ubuntu:~$ <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">at</span> now+<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">5</span> minutes warning: commands will be executed <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">using</span> /bin/sh <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">at</span>> echo <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"hello"</span> > /home/xtwy/hellohello.txt <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">at</span>> <EOT> job <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span> <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">at</span> Tue Sep <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">07</span>:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">21</span>:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">00</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2015</span><span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;"> //檢視程式是否啟動</span> xtwy@ubuntu:~$ <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">at</span> -l <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span> Tue Sep <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">07</span>:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">21</span>:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">00</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2015</span> <span class="hljs-operator" style="box-sizing: border-box;">a</span> xtwy </code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li><li style="box-sizing: border-box; padding: 0px 5px;">5</li><li style="box-sizing: border-box; padding: 0px 5px;">6</li><li style="box-sizing: border-box; padding: 0px 5px;">7</li><li style="box-sizing: border-box; padding: 0px 5px;">8</li><li style="box-sizing: border-box; padding: 0px 5px;">9</li><li style="box-sizing: border-box; padding: 0px 5px;">10</li></ul>
(2)crontab週期性執行作業
crontab 常用選項如下:
-l 顯示當前的crontab
-r 刪除當前的crontab
-e 使用編輯器編輯當前crontab檔案
<code class="hljs coffeescript has-numbering" style="display: block; padding: 0px; color: inherit; box-sizing: border-box; font-family: 'Source Code Pro', monospace;font-size:undefined; white-space: pre; border-radius: 0px; word-wrap: normal; background: transparent;">採用crontab -e 命令進入計劃任務編輯狀態,時間及指令碼設定格式如下: 分鐘 小時 天 月 星期 命令/指令碼 例如在每週五下午<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">6</span>點關機,其命令設定如下: 分鐘 小時 天 月 星期 命令/指令碼 <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">00</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">18</span> * * <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">5</span> /usr/bin/shudown -h now 操作方法: <span class="hljs-regexp" style="color: rgb(0, 136, 0); box-sizing: border-box;">//</span>顯示當前的計劃任務 xtwy<span class="hljs-property" style="box-sizing: border-box;">@ubuntu</span>:~$ crontab -l <span class="hljs-literal" style="color: rgb(0, 102, 102); box-sizing: border-box;">no</span> crontab <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">for</span> xtwy <span class="hljs-regexp" style="color: rgb(0, 136, 0); box-sizing: border-box;">//</span>進入計劃任務編輯狀態 xtwy<span class="hljs-property" style="box-sizing: border-box;">@ubuntu</span>:~$ crontab -e <span class="hljs-literal" style="color: rgb(0, 102, 102); box-sizing: border-box;">no</span> crontab <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">for</span> xtwy - using an empty one Select an editor. To change later, run <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">'select-editor'</span>. <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1.</span> /bin/ed <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2.</span> /bin/nano <---- easiest <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">3.</span> /usr/bin/vim.basic <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">4.</span> /usr/bin/vim.tiny Choose <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>-<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">4</span> [<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2</span>]: <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">3</span> <span class="hljs-attribute" style="box-sizing: border-box; color: rgb(0, 136, 0);">crontab</span>: installing <span class="hljs-keyword" style="color: rgb(0, 0, 136); box-sizing: border-box;">new</span> crontab <span class="hljs-regexp" style="color: rgb(0, 136, 0); box-sizing: border-box;">//</span>設定完成後再進行計劃任務的檢視 xtwy<span class="hljs-property" style="box-sizing: border-box;">@ubuntu</span>:~$ crontab -l <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;"># m h dom mon dow command</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">30</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">9</span> * * <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>-<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">5</span> echo <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"test crontab"</span> >> test.txt 通過下面方式進行檢視計劃: xtwy<span class="hljs-property" style="box-sizing: border-box;">@ubuntu</span>:~$ cd /<span class="hljs-reserved" style="box-sizing: border-box;">var</span>/spool/cron xtwy<span class="hljs-property" style="box-sizing: border-box;">@ubuntu</span>:/<span class="hljs-reserved" style="box-sizing: border-box;">var</span>/spool/cron$ ls atjobs atspool crontabs <span class="hljs-regexp" style="color: rgb(0, 136, 0); box-sizing: border-box;">//</span>crontabs目錄只有root使用者才能檢視 xtwy<span class="hljs-property" style="box-sizing: border-box;">@ubuntu</span>:<span class="hljs-regexp" style="color: rgb(0, 136, 0); box-sizing: border-box;">/var/spool/cron$ cd crontabs/</span> <span class="hljs-attribute" style="box-sizing: border-box; color: rgb(0, 136, 0);">bash</span>: <span class="hljs-attribute" style="box-sizing: border-box; color: rgb(0, 136, 0);">cd</span>: crontabs/: Permission denied xtwy<span class="hljs-property" style="box-sizing: border-box;">@ubuntu</span>:/<span class="hljs-reserved" style="box-sizing: border-box;">var</span>/spool/cron$ su root <span class="hljs-attribute" style="box-sizing: border-box; color: rgb(0, 136, 0);">Password</span>: root<span class="hljs-property" style="box-sizing: border-box;">@ubuntu</span>:<span class="hljs-regexp" style="color: rgb(0, 136, 0); box-sizing: border-box;">/var/spool/cron# cd crontabs/</span> root<span class="hljs-property" style="box-sizing: border-box;">@ubuntu</span>:/<span class="hljs-reserved" style="box-sizing: border-box;">var</span>/spool/cron/crontabs<span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;"># ls</span> xtwy root<span class="hljs-property" style="box-sizing: border-box;">@ubuntu</span>:/<span class="hljs-reserved" style="box-sizing: border-box;">var</span>/spool/cron/crontabs<span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;"># ls -l</span> total <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">4</span> -rw------- <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span> xtwy crontab <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">275</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">2015</span>-<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">09</span>-<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">01</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">17</span>:<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">45</span> xtwy root<span class="hljs-property" style="box-sizing: border-box;">@ubuntu</span>:/<span class="hljs-reserved" style="box-sizing: border-box;">var</span>/spool/cron/crontabs<span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;"># cat xtwy </span> <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;"># DO NOT EDIT THIS FILE - edit the master and reinstall.</span> <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;"># (/tmp/crontab.qUgCZF/crontab installed on Tue Sep 1 17:45:15 2015)</span> <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;"># (Cron version -- $Id: crontab.c,v 2.13 1994/01/17 03:20:37 vixie Exp $)</span> <span class="hljs-comment" style="color: rgb(136, 0, 0); box-sizing: border-box;"># m h dom mon dow command</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">30</span> <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">9</span> * * <span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">1</span>-<span class="hljs-number" style="color: rgb(0, 102, 102); box-sizing: border-box;">5</span> echo <span class="hljs-string" style="color: rgb(0, 136, 0); box-sizing: border-box;">"test crontab"</span> >> test.txt </code><ul class="pre-numbering" style="box-sizing: border-box; position: absolute; width: 50px; top: 0px; left: 0px; margin: 0px; padding: 6px 0px 40px; border-right-width: 1px; border-right-style: solid; border-right-color: rgb(221, 221, 221); list-style: none; text-align: right; background-color: rgb(238, 238, 238);"><li style="box-sizing: border-box; padding: 0px 5px;">1</li><li style="box-sizing: border-box; padding: 0px 5px;">2</li><li style="box-sizing: border-box; padding: 0px 5px;">3</li><li style="box-sizing: border-box; padding: 0px 5px;">4</li><li style="box-sizing: border-box; padding: 0px 5px;">5</li><li style="box-sizing: border-box; padding: 0px 5px;">6</li><li style="box-sizing: border-box; padding: 0px 5px;">7</li><li style="box-sizing: border-box; padding: 0px 5px;">8</li><li style="box-sizing: border-box; padding: 0px 5px;">9</li><li style="box-sizing: border-box; padding: 0px 5px;">10</li><li style="box-sizing: border-box; padding: 0px 5px;">11</li><li style="box-sizing: border-box; padding: 0px 5px;">12</li><li style="box-sizing: border-box; padding: 0px 5px;">13</li><li style="box-sizing: border-box; padding: 0px 5px;">14</li><li style="box-sizing: border-box; padding: 0px 5px;">15</li><li style="box-sizing: border-box; padding: 0px 5px;">16</li><li style="box-sizing: border-box; padding: 0px 5px;">17</li><li style="box-sizing: border-box; padding: 0px 5px;">18</li><li style="box-sizing: border-box; padding: 0px 5px;">19</li><li style="box-sizing: border-box; padding: 0px 5px;">20</li><li style="box-sizing: border-box; padding: 0px 5px;">21</li><li style="box-sizing: border-box; padding: 0px 5px;">22</li><li style="box-sizing: border-box; padding: 0px 5px;">23</li><li style="box-sizing: border-box; padding: 0px 5px;">24</li><li style="box-sizing: border-box; padding: 0px 5px;">25</li><li style="box-sizing: border-box; padding: 0px 5px;">26</li><li style="box-sizing: border-box; padding: 0px 5px;">27</li><li style="box-sizing: border-box; padding: 0px 5px;">28</li><li style="box-sizing: border-box; padding: 0px 5px;">29</li><li style="box-sizing: border-box; padding: 0px 5px;">30</li><li style="box-sizing: border-box; padding: 0px 5px;">31</li><li style="box-sizing: border-box; padding: 0px 5px;">32</li><li style="box-sizing: border-box; padding: 0px 5px;">33</li><li style="box-sizing: border-box; padding: 0px 5px;">34</li><li style="box-sizing: border-box; padding: 0px 5px;">35</li><li style="box-sizing: border-box; padding: 0px 5px;">36</li><li style="box-sizing: border-box; padding: 0px 5px;">37</li><li style="box-sizing: border-box; padding: 0px 5px;">38</li><li style="box-sizing: border-box; padding: 0px 5px;">39</li><li style="box-sizing: border-box; padding: 0px 5px;">40</li><li style="box-sizing: border-box; padding: 0px 5px;">41</li><li style="box-sizing: border-box; padding: 0px 5px;">42</li><li style="box-sizing: border-box; padding: 0px 5px;">43</li><li style="box-sizing: border-box; padding: 0px 5px;">44</li><li style="box-sizing: border-box; padding: 0px 5px;">45</li><li style="box-sizing: border-box; padding: 0px 5px;">46</li><li style="box-sizing: border-box; padding: 0px 5px;">47</li><li style="box-sizing: border-box; padding: 0px 5px;">48</li><li style="box-sizing: border-box; padding: 0px 5px;">49</li><li style="box-sizing: border-box; padding: 0px 5px;">50</li><li style="box-sizing: border-box; padding: 0px 5px;">51</li><li style="box-sizing: border-box; padding: 0px 5px;">52</li></ul>
轉載: http://blog.csdn.net/lovehuangjiaju/article/details/48049919
相關文章
- Spark修煉之道(基礎篇)——Linux大資料開發基礎:第八節:網路管理SparkLinux大資料
- Spark修煉之道(基礎篇)——Linux大資料開發基礎:第三節:使用者和組SparkLinux大資料
- Spark修煉之道(基礎篇)——Linux大資料開發基礎:第十五節:基礎正規表示式(一)SparkLinux大資料
- Spark修煉之道(基礎篇)——Linux大資料開發基礎:第九節:Shell程式設計入門(一)SparkLinux大資料程式設計
- Spark修煉之道(基礎篇)——Linux大資料開發基礎:第十節:Shell程式設計入門(二)SparkLinux大資料程式設計
- Spark修煉之道(基礎篇)——Linux大資料開發基礎:第四節:Linux檔案系統(二)SparkLinux大資料
- Spark修煉之道(基礎篇)——Linux大資料開發基礎:第五節:vi、vim編輯器(一)SparkLinux大資料
- Spark修煉之道(基礎篇)——Linux大資料開發基礎:第六節:vi、vim編輯器(二)SparkLinux大資料
- Spark修煉之道(基礎篇)——Linux大資料開發基礎:第十二節:Shell程式設計入門(四)SparkLinux大資料程式設計
- Spark修煉之道(基礎篇)——Linux大資料開發基礎:第十三節:Shell程式設計入門(五)SparkLinux大資料程式設計
- Spark修煉之道(基礎篇)——Linux大資料開發基礎:第十四節:Shell程式設計入門(六)SparkLinux大資料程式設計
- Spark修煉之道(基礎篇)——Linux大資料開發基礎:第一節、Linux介紹、安裝及使用初步SparkLinux大資料
- Spark修煉之道(基礎篇)——Linux大資料開發基礎:第二節:Linux檔案系統、目錄(一)SparkLinux大資料
- Spark修煉之道(進階篇)——Spark入門到精通:第七節 Spark執行原理Spark
- 【大資料】Spark RDD基礎大資料Spark
- 零基礎入門前端的修煉之道前端
- Spark修煉之道(進階篇)——Spark入門到精通:第四節 Spark程式設計模型(一)Spark程式設計模型
- Spark修煉之道(進階篇)——Spark入門到精通:第五節 Spark程式設計模型(二)Spark程式設計模型
- Spark修煉之道(進階篇)——Spark入門到精通:第六節 Spark程式設計模型(三)Spark程式設計模型
- Linux大資料開發基礎:第三節:使用者和組Linux大資料
- Spark修煉之道(高階篇)——Spark原始碼閱讀:第一節 Spark應用程式提交流程Spark原始碼
- Spark修煉之道(進階篇)——Spark入門到精通:第三節 Spark Intellij IDEA開發環境搭建SparkIntelliJIdea開發環境
- Android開發之道(4)程式框架基礎Android框架
- Linux大資料開發基礎:第四節:Linux檔案系統(二)Linux大資料
- Spark修煉之道(進階篇)——Spark入門到精通:第一節 Spark 1.5.0叢集搭建Spark
- Spark修煉之道(進階篇)——Spark入門到精通:第八節 Spark SQL與DataFrame(一)SparkSQL
- Linux大資料開發基礎:第五節:vi、vim編輯器(一)Linux大資料
- 大資料基礎學習-9.Spark2.1.1大資料Spark
- 大資料基礎之開發第一個Java程式大資料Java
- 大資料解決方案-(基礎篇)大資料
- Spark修煉之道(進階篇)——Spark入門到精通:第二節 Hadoop、Spark生成圈簡介SparkHadoop
- Java基礎 第三節 第七課Java
- C# Xamarin移動開發基礎進修篇C#移動開發
- Spark基礎Spark
- 柳大的Linux講義·基礎篇(4)網路程式設計基礎Linux程式設計
- linux 基礎(10)程式管理Linux
- spark 基礎開發 Tips總結Spark
- scala基礎語法-----Spark基礎Spark