Linux系统命令从入门到完全忘记(五)

2,287次阅读
没有评论

Linux系统命令从入门到完全忘记(五)

进程

ps

概要: 用来显示当前进程的状态

语法格式: ps[参数]

参数:

参数 说明
a 显示所有进程
-a 显示同一终端下的所有程序
-A 显示所有进程
c 显示进程的真实名称
-N 反向选择
-e 等于”-A”
e 显示环境变量
f 显示程序间的关系
-H 显示树状结构
r 显示当前终端的进程
T 显示当前终端的所有程序
u 指定用户的所有进程
-au 显示较详细的资讯
-aux 显示所有包含其他使用者的行程
-C<命令> 列出指定命令的状况
–lines<行数> 每页显示的行数
–width<字符数> 每页显示的字符数

使用示例:

  • 显示所有进程信息
<span class="line">1</span>
<span class="line">2</span>
<span class="line">3</span>
<span class="line">4</span>
<span class="line">5</span>
<span class="line">6</span>
<span class="line">7</span>
<span class="line">8</span>
<span class="line">9</span>
<span class="line">10</span>
<span class="line">11</span>
<span class="line">12</span>
<span class="line">13</span>
<span class="line">14</span>
<span class="line">15</span>
<span class="line">16</span>
<span class="line">17</span>
<span class="line">18</span>
<span class="line">19</span>
<span class="line">20</span>
<span class="line">21</span>
<span class="line">22</span>
<span class="line">23</span>
<span class="line">24</span>
<span class="line">25</span>
<span class="line">26</span>
<span class="line">27</span>
<span class="line">28</span>
<span class="line">29</span>
<span class="line">30</span>
<span class="line">31</span>
<span class="line">32</span>
<span class="line">33</span>
<span class="line">34</span>
<span class="line">35</span>
<span class="line">36</span>
<span class="line">37</span>
<span class="line">38</span>
<span class="line">39</span>
<span class="line">40</span>
<span class="line">41</span>
<span class="line">42</span>
<span class="line">43</span>
<span class="line">44</span>
<span class="line">45</span>
<span class="line">46</span>
<span class="line">47</span>
<span class="line">48</span>
<span class="line">49</span>
<span class="line">50</span>
<span class="line">51</span>
<span class="line">52</span>
<span class="line">53</span>
<span class="line">54</span>
<span class="line">55</span>
<span class="line">56</span>
<span class="line">57</span>
<span class="line">58</span>
<span class="line">59</span>
<span class="line">60</span>
<span class="line">61</span>
<span class="line">62</span>
<span class="line">63</span>
<span class="line">64</span>
<span class="line">65</span>
<span class="line">66</span>
<span class="line">67</span>
<span class="line">68</span>
<span class="line">69</span>
<span class="line">70</span>
<span class="line">71</span>
<span class="line">72</span>
<span class="line">73</span>
<span class="line">74</span>
<span class="line">75</span>
<span class="line">76</span>
<span class="line">77</span>
<span class="line">78</span>
<span class="line">79</span>
<span class="line">80</span>
<span class="line">81</span>
<span class="line">82</span>
<span class="line">83</span>
<span class="line">84</span>
<span class="line">85</span>
<span class="line">86</span>
<span class="line">87</span>
<span class="line">88</span>
<span class="line">[root@ansheng ~]<span class="comment"># ps -A</span></span>
<span class="line">   PID TTY          TIME CMD</span>
<span class="line">     1 ?        00:00:01 init</span>
<span class="line">     2 ?        00:00:00 kthreadd</span>
<span class="line">     3 ?        00:00:00 migration/0</span>
<span class="line">     4 ?        00:00:00 ksoftirqd/0</span>
<span class="line">     5 ?        00:00:00 stopper/0</span>
<span class="line">     6 ?        00:00:00 watchdog/0</span>
<span class="line">     7 ?        00:00:00 migration/1</span>
<span class="line">     8 ?        00:00:00 stopper/1</span>
<span class="line">     9 ?        00:00:00 ksoftirqd/1</span>
<span class="line">    10 ?        00:00:00 watchdog/1</span>
<span class="line">    11 ?        00:00:00 events/0</span>
<span class="line">    12 ?        00:00:00 events/1</span>
<span class="line">    13 ?        00:00:00 events/0</span>
<span class="line">    14 ?        00:00:00 events/1</span>
<span class="line">    15 ?        00:00:00 events_long/0</span>
<span class="line">    16 ?        00:00:00 events_long/1</span>
<span class="line">    17 ?        00:00:00 events_power_ef</span>
<span class="line">    18 ?        00:00:00 events_power_ef</span>
<span class="line">    19 ?        00:00:00 cgroup</span>
<span class="line">    20 ?        00:00:00 khelper</span>
<span class="line">    21 ?        00:00:00 netns</span>
<span class="line">    22 ?        00:00:00 async/mgr</span>
<span class="line">    23 ?        00:00:00 pm</span>
<span class="line">    24 ?        00:00:00 sync_supers</span>
<span class="line">    25 ?        00:00:00 bdi-default</span>
<span class="line">    26 ?        00:00:00 kintegrityd/0</span>
<span class="line">    27 ?        00:00:00 kintegrityd/1</span>
<span class="line">    28 ?        00:00:00 kblockd/0</span>
<span class="line">    29 ?        00:00:00 kblockd/1</span>
<span class="line">    30 ?        00:00:00 kacpid</span>
<span class="line">    31 ?        00:00:00 kacpi_notify</span>
<span class="line">    32 ?        00:00:00 kacpi_hotplug</span>
<span class="line">    33 ?        00:00:00 ata_aux</span>
<span class="line">    34 ?        00:00:00 ata_sff/0</span>
<span class="line">    35 ?        00:00:00 ata_sff/1</span>
<span class="line">    36 ?        00:00:00 ksuspend_usbd</span>
<span class="line">    37 ?        00:00:00 khubd</span>
<span class="line">    38 ?        00:00:00 kseriod</span>
<span class="line">    39 ?        00:00:00 md/0</span>
<span class="line">    40 ?        00:00:00 md/1</span>
<span class="line">    41 ?        00:00:00 md_misc/0</span>
<span class="line">    42 ?        00:00:00 md_misc/1</span>
<span class="line">    43 ?        00:00:00 linkwatch</span>
<span class="line">    45 ?        00:00:00 khungtaskd</span>
<span class="line">    46 ?        00:00:00 kswapd0</span>
<span class="line">    47 ?        00:00:00 ksmd</span>
<span class="line">    48 ?        00:00:00 khugepaged</span>
<span class="line">    49 ?        00:00:00 aio/0</span>
<span class="line">    50 ?        00:00:00 aio/1</span>
<span class="line">    51 ?        00:00:00 crypto/0</span>
<span class="line">    52 ?        00:00:00 crypto/1</span>
<span class="line">    59 ?        00:00:00 kthrotld/0</span>
<span class="line">    60 ?        00:00:00 kthrotld/1</span>
<span class="line">    61 ?        00:00:00 pciehpd</span>
<span class="line">    63 ?        00:00:00 kpsmoused</span>
<span class="line">    64 ?        00:00:00 usbhid_resumer</span>
<span class="line">    65 ?        00:00:00 deferwq</span>
<span class="line">    97 ?        00:00:00 kdmremove</span>
<span class="line">    98 ?        00:00:00 kstriped</span>
<span class="line">   223 ?        00:00:00 mpt_poll_0</span>
<span class="line">   224 ?        00:00:00 mpt/0</span>
<span class="line">   225 ?        00:00:00 scsi_eh_0</span>
<span class="line">   228 ?        00:00:00 scsi_eh_1</span>
<span class="line">   229 ?        00:00:00 scsi_eh_2</span>
<span class="line">   347 ?        00:00:00 jbd2/sda3-8</span>
<span class="line">   348 ?        00:00:00 ext4-dio-unwrit</span>
<span class="line">   444 ?        00:00:00 udevd</span>
<span class="line">   629 ?        00:00:00 vmmemctl</span>
<span class="line">   731 ?        00:00:00 udevd</span>
<span class="line">   763 ?        00:00:00 jbd2/sda1-8</span>
<span class="line">   764 ?        00:00:00 ext4-dio-unwrit</span>
<span class="line">   796 ?        00:00:00 kauditd</span>
<span class="line">   823 ?        00:00:00 flush-8:0</span>
<span class="line">   979 ?        00:00:00 rsyslogd</span>
<span class="line">   999 ?        00:00:00 sshd</span>
<span class="line">  1011 ?        00:00:00 crond</span>
<span class="line">  1024 tty1     00:00:00 mingetty</span>
<span class="line">  1026 tty2     00:00:00 mingetty</span>
<span class="line">  1028 tty3     00:00:00 mingetty</span>
<span class="line">  1030 tty4     00:00:00 mingetty</span>
<span class="line">  1031 ?        00:00:00 udevd</span>
<span class="line">  1033 tty5     00:00:00 mingetty</span>
<span class="line">  1035 tty6     00:00:00 mingetty</span>
<span class="line">  1037 ?        00:00:00 sshd</span>
<span class="line">  1039 pts/0    00:00:00 bash</span>
<span class="line">  1115 pts/0    00:00:00 ps</span>
  • 显示指定用户信息
<span class="line">1</span>
<span class="line">2</span>
<span class="line">3</span>
<span class="line">4</span>
<span class="line">5</span>
<span class="line">6</span>
<span class="line">7</span>
<span class="line">8</span>
<span class="line">9</span>
<span class="line">10</span>
<span class="line">11</span>
<span class="line">12</span>
<span class="line">13</span>
<span class="line">14</span>
<span class="line">15</span>
<span class="line">16</span>
<span class="line">17</span>
<span class="line">18</span>
<span class="line">19</span>
<span class="line">20</span>
<span class="line">21</span>
<span class="line">22</span>
<span class="line">23</span>
<span class="line">24</span>
<span class="line">25</span>
<span class="line">26</span>
<span class="line">27</span>
<span class="line">28</span>
<span class="line">29</span>
<span class="line">30</span>
<span class="line">31</span>
<span class="line">32</span>
<span class="line">33</span>
<span class="line">34</span>
<span class="line">35</span>
<span class="line">36</span>
<span class="line">37</span>
<span class="line">38</span>
<span class="line">39</span>
<span class="line">40</span>
<span class="line">41</span>
<span class="line">42</span>
<span class="line">43</span>
<span class="line">44</span>
<span class="line">45</span>
<span class="line">46</span>
<span class="line">47</span>
<span class="line">48</span>
<span class="line">49</span>
<span class="line">50</span>
<span class="line">51</span>
<span class="line">52</span>
<span class="line">53</span>
<span class="line">54</span>
<span class="line">55</span>
<span class="line">56</span>
<span class="line">57</span>
<span class="line">58</span>
<span class="line">59</span>
<span class="line">60</span>
<span class="line">61</span>
<span class="line">62</span>
<span class="line">63</span>
<span class="line">64</span>
<span class="line">65</span>
<span class="line">66</span>
<span class="line">67</span>
<span class="line">68</span>
<span class="line">69</span>
<span class="line">70</span>
<span class="line">71</span>
<span class="line">72</span>
<span class="line">73</span>
<span class="line">74</span>
<span class="line">75</span>
<span class="line">76</span>
<span class="line">77</span>
<span class="line">78</span>
<span class="line">79</span>
<span class="line">80</span>
<span class="line">81</span>
<span class="line">82</span>
<span class="line">83</span>
<span class="line">84</span>
<span class="line">85</span>
<span class="line">86</span>
<span class="line">87</span>
<span class="line">88</span>
<span class="line">[root@ansheng ~]<span class="comment"># ps -u root</span></span>
<span class="line">   PID TTY          TIME CMD</span>
<span class="line">     1 ?        00:00:01 init</span>
<span class="line">     2 ?        00:00:00 kthreadd</span>
<span class="line">     3 ?        00:00:00 migration/0</span>
<span class="line">     4 ?        00:00:00 ksoftirqd/0</span>
<span class="line">     5 ?        00:00:00 stopper/0</span>
<span class="line">     6 ?        00:00:00 watchdog/0</span>
<span class="line">     7 ?        00:00:00 migration/1</span>
<span class="line">     8 ?        00:00:00 stopper/1</span>
<span class="line">     9 ?        00:00:00 ksoftirqd/1</span>
<span class="line">    10 ?        00:00:00 watchdog/1</span>
<span class="line">    11 ?        00:00:00 events/0</span>
<span class="line">    12 ?        00:00:00 events/1</span>
<span class="line">    13 ?        00:00:00 events/0</span>
<span class="line">    14 ?        00:00:00 events/1</span>
<span class="line">    15 ?        00:00:00 events_long/0</span>
<span class="line">    16 ?        00:00:00 events_long/1</span>
<span class="line">    17 ?        00:00:00 events_power_ef</span>
<span class="line">    18 ?        00:00:00 events_power_ef</span>
<span class="line">    19 ?        00:00:00 cgroup</span>
<span class="line">    20 ?        00:00:00 khelper</span>
<span class="line">    21 ?        00:00:00 netns</span>
<span class="line">    22 ?        00:00:00 async/mgr</span>
<span class="line">    23 ?        00:00:00 pm</span>
<span class="line">    24 ?        00:00:00 sync_supers</span>
<span class="line">    25 ?        00:00:00 bdi-default</span>
<span class="line">    26 ?        00:00:00 kintegrityd/0</span>
<span class="line">    27 ?        00:00:00 kintegrityd/1</span>
<span class="line">    28 ?        00:00:00 kblockd/0</span>
<span class="line">    29 ?        00:00:00 kblockd/1</span>
<span class="line">    30 ?        00:00:00 kacpid</span>
<span class="line">    31 ?        00:00:00 kacpi_notify</span>
<span class="line">    32 ?        00:00:00 kacpi_hotplug</span>
<span class="line">    33 ?        00:00:00 ata_aux</span>
<span class="line">    34 ?        00:00:00 ata_sff/0</span>
<span class="line">    35 ?        00:00:00 ata_sff/1</span>
<span class="line">    36 ?        00:00:00 ksuspend_usbd</span>
<span class="line">    37 ?        00:00:00 khubd</span>
<span class="line">    38 ?        00:00:00 kseriod</span>
<span class="line">    39 ?        00:00:00 md/0</span>
<span class="line">    40 ?        00:00:00 md/1</span>
<span class="line">    41 ?        00:00:00 md_misc/0</span>
<span class="line">    42 ?        00:00:00 md_misc/1</span>
<span class="line">    43 ?        00:00:00 linkwatch</span>
<span class="line">    45 ?        00:00:00 khungtaskd</span>
<span class="line">    46 ?        00:00:00 kswapd0</span>
<span class="line">    47 ?        00:00:00 ksmd</span>
<span class="line">    48 ?        00:00:00 khugepaged</span>
<span class="line">    49 ?        00:00:00 aio/0</span>
<span class="line">    50 ?        00:00:00 aio/1</span>
<span class="line">    51 ?        00:00:00 crypto/0</span>
<span class="line">    52 ?        00:00:00 crypto/1</span>
<span class="line">    59 ?        00:00:00 kthrotld/0</span>
<span class="line">    60 ?        00:00:00 kthrotld/1</span>
<span class="line">    61 ?        00:00:00 pciehpd</span>
<span class="line">    63 ?        00:00:00 kpsmoused</span>
<span class="line">    64 ?        00:00:00 usbhid_resumer</span>
<span class="line">    65 ?        00:00:00 deferwq</span>
<span class="line">    97 ?        00:00:00 kdmremove</span>
<span class="line">    98 ?        00:00:00 kstriped</span>
<span class="line">   223 ?        00:00:00 mpt_poll_0</span>
<span class="line">   224 ?        00:00:00 mpt/0</span>
<span class="line">   225 ?        00:00:00 scsi_eh_0</span>
<span class="line">   228 ?        00:00:00 scsi_eh_1</span>
<span class="line">   229 ?        00:00:00 scsi_eh_2</span>
<span class="line">   347 ?        00:00:00 jbd2/sda3-8</span>
<span class="line">   348 ?        00:00:00 ext4-dio-unwrit</span>
<span class="line">   444 ?        00:00:00 udevd</span>
<span class="line">   629 ?        00:00:00 vmmemctl</span>
<span class="line">   731 ?        00:00:00 udevd</span>
<span class="line">   763 ?        00:00:00 jbd2/sda1-8</span>
<span class="line">   764 ?        00:00:00 ext4-dio-unwrit</span>
<span class="line">   796 ?        00:00:00 kauditd</span>
<span class="line">   823 ?        00:00:00 flush-8:0</span>
<span class="line">   979 ?        00:00:00 rsyslogd</span>
<span class="line">   999 ?        00:00:00 sshd</span>
<span class="line">  1011 ?        00:00:00 crond</span>
<span class="line">  1024 tty1     00:00:00 mingetty</span>
<span class="line">  1026 tty2     00:00:00 mingetty</span>
<span class="line">  1028 tty3     00:00:00 mingetty</span>
<span class="line">  1030 tty4     00:00:00 mingetty</span>
<span class="line">  1031 ?        00:00:00 udevd</span>
<span class="line">  1033 tty5     00:00:00 mingetty</span>
<span class="line">  1035 tty6     00:00:00 mingetty</span>
<span class="line">  1037 ?        00:00:00 sshd</span>
<span class="line">  1039 pts/0    00:00:00 bash</span>
<span class="line">  1122 pts/0    00:00:00 ps</span>
  • 显示所有进程信息,连同命令行
<span class="line">1</span>
<span class="line">2</span>
<span class="line">3</span>
<span class="line">4</span>
<span class="line">5</span>
<span class="line">6</span>
<span class="line">7</span>
<span class="line">8</span>
<span class="line">9</span>
<span class="line">10</span>
<span class="line">11</span>
<span class="line">12</span>
<span class="line">13</span>
<span class="line">14</span>
<span class="line">15</span>
<span class="line">16</span>
<span class="line">17</span>
<span class="line">18</span>
<span class="line">19</span>
<span class="line">20</span>
<span class="line">21</span>
<span class="line">22</span>
<span class="line">23</span>
<span class="line">24</span>
<span class="line">25</span>
<span class="line">26</span>
<span class="line">27</span>
<span class="line">28</span>
<span class="line">29</span>
<span class="line">30</span>
<span class="line">31</span>
<span class="line">32</span>
<span class="line">33</span>
<span class="line">34</span>
<span class="line">35</span>
<span class="line">36</span>
<span class="line">37</span>
<span class="line">38</span>
<span class="line">39</span>
<span class="line">40</span>
<span class="line">41</span>
<span class="line">42</span>
<span class="line">43</span>
<span class="line">44</span>
<span class="line">45</span>
<span class="line">46</span>
<span class="line">47</span>
<span class="line">48</span>
<span class="line">49</span>
<span class="line">50</span>
<span class="line">51</span>
<span class="line">52</span>
<span class="line">53</span>
<span class="line">54</span>
<span class="line">55</span>
<span class="line">56</span>
<span class="line">57</span>
<span class="line">58</span>
<span class="line">59</span>
<span class="line">60</span>
<span class="line">61</span>
<span class="line">62</span>
<span class="line">63</span>
<span class="line">64</span>
<span class="line">65</span>
<span class="line">66</span>
<span class="line">67</span>
<span class="line">68</span>
<span class="line">69</span>
<span class="line">70</span>
<span class="line">71</span>
<span class="line">72</span>
<span class="line">73</span>
<span class="line">74</span>
<span class="line">75</span>
<span class="line">76</span>
<span class="line">77</span>
<span class="line">78</span>
<span class="line">79</span>
<span class="line">80</span>
<span class="line">81</span>
<span class="line">82</span>
<span class="line">83</span>
<span class="line">84</span>
<span class="line">85</span>
<span class="line">86</span>
<span class="line">87</span>
<span class="line">88</span>
<span class="line">Warning: bad syntax, perhaps a bogus <span class="string">'-'</span>? See /usr/share/doc/procps-3.2.8/FAQ</span>
<span class="line">USER        PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND</span>
<span class="line">root          1  0.1  0.0  19232  1512 ?        Ss   21:20   0:01 /sbin/init</span>
<span class="line">root          2  0.0  0.0      0     0 ?        S    21:20   0:00 [kthreadd]</span>
<span class="line">root          3  0.0  0.0      0     0 ?        S    21:20   0:00 [migration/0]</span>
<span class="line">root          4  0.0  0.0      0     0 ?        S    21:20   0:00 [ksoftirqd/0]</span>
<span class="line">root          5  0.0  0.0      0     0 ?        S    21:20   0:00 [stopper/0]</span>
<span class="line">root          6  0.0  0.0      0     0 ?        S    21:20   0:00 [watchdog/0]</span>
<span class="line">root          7  0.0  0.0      0     0 ?        S    21:20   0:00 [migration/1]</span>
<span class="line">root          8  0.0  0.0      0     0 ?        S    21:20   0:00 [stopper/1]</span>
<span class="line">root          9  0.0  0.0      0     0 ?        S    21:20   0:00 [ksoftirqd/1]</span>
<span class="line">root         10  0.0  0.0      0     0 ?        S    21:20   0:00 [watchdog/1]</span>
<span class="line">root         11  0.0  0.0      0     0 ?        S    21:20   0:00 [events/0]</span>
<span class="line">root         12  0.0  0.0      0     0 ?        R    21:20   0:00 [events/1]</span>
<span class="line">root         13  0.0  0.0      0     0 ?        S    21:20   0:00 [events/0]</span>
<span class="line">root         14  0.0  0.0      0     0 ?        S    21:20   0:00 [events/1]</span>
<span class="line">root         15  0.0  0.0      0     0 ?        S    21:20   0:00 [events_long/0]</span>
<span class="line">root         16  0.0  0.0      0     0 ?        S    21:20   0:00 [events_long/1]</span>
<span class="line">root         17  0.0  0.0      0     0 ?        S    21:20   0:00 [events_power_ef]</span>
<span class="line">root         18  0.0  0.0      0     0 ?        S    21:20   0:00 [events_power_ef]</span>
<span class="line">root         19  0.0  0.0      0     0 ?        S    21:20   0:00 [cgroup]</span>
<span class="line">root         20  0.0  0.0      0     0 ?        S    21:20   0:00 [khelper]</span>
<span class="line">root         21  0.0  0.0      0     0 ?        S    21:20   0:00 [netns]</span>
<span class="line">root         22  0.0  0.0      0     0 ?        S    21:20   0:00 [async/mgr]</span>
<span class="line">root         23  0.0  0.0      0     0 ?        S    21:20   0:00 [pm]</span>
<span class="line">root         24  0.0  0.0      0     0 ?        S    21:20   0:00 [sync_supers]</span>
<span class="line">root         25  0.0  0.0      0     0 ?        S    21:20   0:00 [bdi-default]</span>
<span class="line">root         26  0.0  0.0      0     0 ?        S    21:20   0:00 [kintegrityd/0]</span>
<span class="line">root         27  0.0  0.0      0     0 ?        S    21:20   0:00 [kintegrityd/1]</span>
<span class="line">root         28  0.0  0.0      0     0 ?        S    21:20   0:00 [kblockd/0]</span>
<span class="line">root         29  0.0  0.0      0     0 ?        S    21:20   0:00 [kblockd/1]</span>
<span class="line">root         30  0.0  0.0      0     0 ?        S    21:20   0:00 [kacpid]</span>
<span class="line">root         31  0.0  0.0      0     0 ?        S    21:20   0:00 [kacpi_notify]</span>
<span class="line">root         32  0.0  0.0      0     0 ?        S    21:20   0:00 [kacpi_hotplug]</span>
<span class="line">root         33  0.0  0.0      0     0 ?        S    21:20   0:00 [ata_aux]</span>
<span class="line">root         34  0.0  0.0      0     0 ?        S    21:20   0:00 [ata_sff/0]</span>
<span class="line">root         35  0.0  0.0      0     0 ?        S    21:20   0:00 [ata_sff/1]</span>
<span class="line">root         36  0.0  0.0      0     0 ?        S    21:20   0:00 [ksuspend_usbd]</span>
<span class="line">root         37  0.0  0.0      0     0 ?        S    21:20   0:00 [khubd]</span>
<span class="line">root         38  0.0  0.0      0     0 ?        S    21:20   0:00 [kseriod]</span>
<span class="line">root         39  0.0  0.0      0     0 ?        S    21:20   0:00 [md/0]</span>
<span class="line">root         40  0.0  0.0      0     0 ?        S    21:20   0:00 [md/1]</span>
<span class="line">root         41  0.0  0.0      0     0 ?        S    21:20   0:00 [md_misc/0]</span>
<span class="line">root         42  0.0  0.0      0     0 ?        S    21:20   0:00 [md_misc/1]</span>
<span class="line">root         43  0.0  0.0      0     0 ?        S    21:20   0:00 [linkwatch]</span>
<span class="line">root         45  0.0  0.0      0     0 ?        S    21:20   0:00 [khungtaskd]</span>
<span class="line">root         46  0.0  0.0      0     0 ?        S    21:20   0:00 [kswapd0]</span>
<span class="line">root         47  0.0  0.0      0     0 ?        SN   21:20   0:00 [ksmd]</span>
<span class="line">root         48  0.0  0.0      0     0 ?        SN   21:20   0:00 [khugepaged]</span>
<span class="line">root         49  0.0  0.0      0     0 ?        S    21:20   0:00 [aio/0]</span>
<span class="line">root         50  0.0  0.0      0     0 ?        S    21:20   0:00 [aio/1]</span>
<span class="line">root         51  0.0  0.0      0     0 ?        S    21:20   0:00 [crypto/0]</span>
<span class="line">root         52  0.0  0.0      0     0 ?        S    21:20   0:00 [crypto/1]</span>
<span class="line">root         59  0.0  0.0      0     0 ?        S    21:20   0:00 [kthrotld/0]</span>
<span class="line">root         60  0.0  0.0      0     0 ?        S    21:20   0:00 [kthrotld/1]</span>
<span class="line">root         61  0.0  0.0      0     0 ?        S    21:20   0:00 [pciehpd]</span>
<span class="line">root         63  0.0  0.0      0     0 ?        S    21:20   0:00 [kpsmoused]</span>
<span class="line">root         64  0.0  0.0      0     0 ?        S    21:20   0:00 [usbhid_resumer]</span>
<span class="line">root         65  0.0  0.0      0     0 ?        S    21:20   0:00 [deferwq]</span>
<span class="line">root         97  0.0  0.0      0     0 ?        S    21:20   0:00 [kdmremove]</span>
<span class="line">root         98  0.0  0.0      0     0 ?        S    21:20   0:00 [kstriped]</span>
<span class="line">root        223  0.0  0.0      0     0 ?        S    21:20   0:00 [mpt_poll_0]</span>
<span class="line">root        224  0.0  0.0      0     0 ?        S    21:20   0:00 [mpt/0]</span>
<span class="line">root        225  0.0  0.0      0     0 ?        S    21:20   0:00 [scsi_eh_0]</span>
<span class="line">root        228  0.0  0.0      0     0 ?        S    21:20   0:00 [scsi_eh_1]</span>
<span class="line">root        229  0.0  0.0      0     0 ?        S    21:20   0:00 [scsi_eh_2]</span>
<span class="line">root        347  0.0  0.0      0     0 ?        S    21:20   0:00 [jbd2/sda3-8]</span>
<span class="line">root        348  0.0  0.0      0     0 ?        S    21:20   0:00 [ext4-dio-unwrit]</span>
<span class="line">root        444  0.0  0.0  10880   932 ?        S<\s  21:20   0:00 /sbin/udevd <span class="_">-d</span></span>
<span class="line">root        629  0.0  0.0      0     0 ?        S    21:20   0:00 [vmmemctl]</span>
<span class="line">root        731  0.0  0.0  10808   928 ?        S<   21:20   0:00 /sbin/udevd <span class="_">-d</span></span>
<span class="line">root        763  0.0  0.0      0     0 ?        S    21:20   0:00 [jbd2/sda1-8]</span>
<span class="line">root        764  0.0  0.0      0     0 ?        S    21:20   0:00 [ext4-dio-unwrit]</span>
<span class="line">root        796  0.0  0.0      0     0 ?        S    21:20   0:00 [kauditd]</span>
<span class="line">root        823  0.0  0.0      0     0 ?        S    21:20   0:00 [flush-8:0]</span>
<span class="line">root        979  0.0  0.1 255424  3684 ?        Sl   21:20   0:00 /sbin/rsyslogd -i /var/run/syslogd.pid -c 5</span>
<span class="line">root        999  0.0  0.0  66232  1188 ?        Ss   21:20   0:00 /usr/sbin/sshd</span>
<span class="line">root       1011  0.0  0.0 116864  1260 ?        Ss   21:20   0:00 crond</span>
<span class="line">root       1024  0.0  0.0   4064   548 tty1     Ss+  21:20   0:00 /sbin/mingetty /dev/tty1</span>
<span class="line">root       1026  0.0  0.0   4064   548 tty2     Ss+  21:20   0:00 /sbin/mingetty /dev/tty2</span>
<span class="line">root       1028  0.0  0.0   4064   548 tty3     Ss+  21:20   0:00 /sbin/mingetty /dev/tty3</span>
<span class="line">root       1030  0.0  0.0   4064   544 tty4     Ss+  21:20   0:00 /sbin/mingetty /dev/tty4</span>
<span class="line">root       1031  0.0  0.0  10812   908 ?        S<   21:20   0:00 /sbin/udevd <span class="_">-d</span></span>
<span class="line">root       1033  0.0  0.0   4064   548 tty5     Ss+  21:20   0:00 /sbin/mingetty /dev/tty5</span>
<span class="line">root       1035  0.0  0.0   4064   548 tty6     Ss+  21:20   0:00 /sbin/mingetty /dev/tty6</span>
<span class="line">root       1037  0.0  0.2 100440  4408 ?        Ss   21:20   0:00 sshd: root@pts/0 </span>
<span class="line">root       1039  0.0  0.0 108464  1876 pts/0    Ss   21:20   0:00 -bash</span>
<span class="line">root       1123  0.0  0.0 110236  1140 pts/0    R+   21:35   0:00 ps -aux</span>

进程管理

bg

概要: bg命令用于将作业放到后台运行,使前台可以执行其他任务。

语法格式: bg [参数]

使用示例:

  • 使用bg命令将任务号为1的任务放到后台继续执行,输入如下命令:
<span class="line">1</span>
<span class="line">[root@ansheng ~]<span class="comment"># bg 1</span></span>

fg

概要: fg命令用于将后台作业(在后台运行的或者在后台挂起的作业)放到前台终端运行。与bg命令一样,若后台任务中只有一个,则使用该命令时,可以省略任务号。

语法格式: fg [参数]

使用示例:

  • 使用fg命令将任务号为1的任务从后台执行转换到前台执行
<span class="line">1</span>
<span class="line">[root@ansheng ~]<span class="comment"># fg 1</span></span>

jobs

概要: jobs命令用于显示Linux中的任务列表及任务状态,包括后台运行的任务。

语法格式: jobs [选项] [参数]

参数:

参数 说明
-l 显示进程号
-p 仅任务对应的显示进程号
-n 显示任务状态的变化
-r 仅输出运行状态(running)的任务
-s 仅输出停止状态(stoped)的任务

使用示例:

  • 使用jobs命令显示当前系统的任务列表
<span class="line">1</span>
<span class="line">[root@ansheng ~]<span class="comment"># jobs -l</span></span>

kill

概要: kill命令用来删除执行中的程序或工作

语法格式: kill [选项] [参数]

参数:

参数 说明
-a 当处理当前进程时,不限制命令名和进程号的对应关系
-l <信息编号> 若不加<信息编号>选项,则-l参数会列出全部的信息名称
-p 指定kill 命令只打印相关进程的进程号,而不发送任何信号
-s <信息名称或编号> 指定要送出的信息
-u 指定用户

使用示例:

  • 杀掉vim进程
<span class="line">1</span>
2
3
4
5
6
<span class="line">[root@ansheng ~]<span class="comment"># ps -ef | grep "vim"</span></span>
<span class="line">root       1167   1141  0 21:45 pts/1    00:00:00 vim</span>
<span class="line">root       1169   1039  0 21:45 pts/0    00:00:00 grep vim</span>
<span class="line">[root@ansheng ~]<span class="comment"># kill -9 1167</span></span>
<span class="line">[root@ansheng ~]<span class="comment"># ps -ef | grep "vim"</span></span>
<span class="line">root       1173   1039  0 21:45 pts/0    00:00:00 grep vim</span>

信号说明

型号 说明
HUP 1 终端断线
INT 2 中断(同 Ctrl + C)
QUIT 3 退出(同 Ctrl + \)
TERM 15 终止
KILL 9 强制终止
CONT 18 继续(与STOP相反, fg/bg命令)
STOP 19 暂停(同 Ctrl + Z)

killall

概要: killall命令使用进程的名称来杀死进程,使用此指令可以杀死一组同名进程。

语法格式: killall [选项] [参数]

参数:

参数 说明
-e 对长名称进行精确匹配
-l 忽略大小写的不同
-p 杀死进程所属的进程组
-i 交互式杀死进程,杀死进程前需要进行确认
-l 打印所有已知信号列表
-q 如果没有进程被杀死。则不输出任何信息
-r 使用正规表达式匹配要杀死的进程名称
-s 用指定的进程号代替默认信号”SIGTERM”
-u 杀死指定用户的进程

使用示例:

  • 杀死所有vi同名进程
<span class="line">1</span>
<span class="line">[root@ansheng ~]<span class="comment"># killall vi</span></span>

pkill

概要: 按照进程名杀死进程

语法格式: pkill [选项] [参数]

参数:

参数 说明
-o 仅向找到的最小(起始)进程号发送信号
-n 仅向找到的最大(结束)进程号发送信号
-P 指定父进程号发送信号
-g 指定进程组
-t 指定开启进程的终端

使用示例:

  • 杀掉进程hexo
<span class="line">1</span>
<span class="line">[root@ansheng ~]<span class="comment"># pkill hexo</span></span>

pstree

概要: 以树状图的方式展现进程之间的派生关系,显示效果比较直观。

语法格式: pstree [选项]

参数:

参数 说明
-a 显示每个程序的完整指令,包含路径,参数或是常驻服务的标示
-c 不使用精简标示法
-G 使用VT100终端机的列绘图字符
-h 列出树状图时,特别标明现在执行的程序
-H<程序识别码> 此参数的效果和指定”-h”参数类似,但特别标明指定的程序
-l 采用长列格式显示树状图
-n 用程序识别码排序。预设是以程序名称来排序
-p 显示程序识别码
-u 显示用户名称
-U 使用UTF-8列绘图字符

使用示例:

  • 显示当前所有进程的进程号和进程id
<span class="line">1</span>
2
3
4
5
6
7
8
9
10
11
12
13
14
15
<span class="line">[root@ansheng ~]<span class="comment"># pstree -p</span></span>
<span class="line">init(1)─┬─crond(1011)</span>
<span class="line">        ├─mingetty(1024)</span>
<span class="line">        ├─mingetty(1026)</span>
<span class="line">        ├─mingetty(1028)</span>
<span class="line">        ├─mingetty(1030)</span>
<span class="line">        ├─mingetty(1033)</span>
<span class="line">        ├─mingetty(1035)</span>
<span class="line">        ├─rsyslogd(979)─┬─{rsyslogd}(980)</span>
<span class="line">        │               ├─{rsyslogd}(981)</span>
<span class="line">        │               └─{rsyslogd}(987)</span>
<span class="line">        ├─sshd(999)───sshd(1037)─┬─bash(1039)───pstree(1191)</span>
<span class="line">        │                        └─bash(1141)</span>
<span class="line">        └─udevd(444)─┬─udevd(731)</span>
<span class="line">                     └─udevd(1031)</span>
  • 显示所有进程的所有详细信息,遇到相同的进程名可以压缩显示。
<span class="line">1</span>
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
<span class="line">[root@ansheng ~]<span class="comment"># pstree -a</span></span>
<span class="line">init</span>
<span class="line">  ├─crond</span>
<span class="line">  ├─mingetty /dev/tty1</span>
<span class="line">  ├─mingetty /dev/tty2</span>
<span class="line">  ├─mingetty /dev/tty3</span>
<span class="line">  ├─mingetty /dev/tty4</span>
<span class="line">  ├─mingetty /dev/tty5</span>
<span class="line">  ├─mingetty /dev/tty6</span>
<span class="line">  ├─rsyslogd -i /var/run/syslogd.pid -c 5</span>
<span class="line">  │   ├─{rsyslogd}</span>
<span class="line">  │   ├─{rsyslogd}</span>
<span class="line">  │   └─{rsyslogd}</span>
<span class="line">  ├─sshd</span>
<span class="line">  │   └─sshd</span>
<span class="line">  │       ├─bash</span>
<span class="line">  │       │   └─pstree <span class="_">-a</span></span>
<span class="line">  │       └─bash</span>
<span class="line">  └─udevd <span class="_">-d</span></span>
<span class="line">      ├─udevd <span class="_">-d</span></span>
<span class="line">      └─udevd <span class="_">-d</span></span>

nohup

概要: 将程序以忽略挂起信号的方式运行起来,被运行的程序的输出信息将不会显示到终端。

语法格式: nohup [选项] [参数]

使用示例:

  • 后台运行ps命令
<span class="line">1</span>
<span class="line">[root@ansheng ~]<span class="comment"># nohup ps > /tmp/myout.file 2>&1 &</span></span>
admin
版权声明:本站原创文章,由admin2016-07-12发表,共计10189字。
转载提示:除特殊说明外本站文章皆由CC-4.0协议发布,转载请注明出处。
评论(没有评论)