zoukankan      html  css  js  c++  java
  • 系统进程

    本博文的主要内容有

      .进程简介

      .查看linux系统进程的分布结构

      .查看linux系统当前,有哪些进程在运行

      .对linux系统进行动态监控

      .进程的创建和终止

      .什么是后台进程

      .什么时候使用后台进程

    1、进程简介

    2、系统进程信息

    3、进程创建

    4、进程终止

    进程简介

      系统启动的第一个进程是init进程,系统中的其他进程都由此进程产生并受它控制。所谓进程,被认为是一个具有独立功能的程序,在一个数据集合上的一次动态执行过程。但,需要注意,一个进程只能对应一个程序。

      进程通常由3部分组成:程序、数据集合和进程控制块(PCB)。

      在linux系统中,每一个进程都有一个唯一的标识符,即进程ID,简称PID。此PID是在进程启动进程启动时系统为其分配的,除了init进程外,其他进程都是系统通过调研fork()和clone()函数创建的进程。

    系统进程信息 

      pstree         查看linux系统中进程的分布结构  

      出现,这种现象,是编码的问题而已。鼠标,放到会话窗口,右键,点击Session Options,

    [root@weekend110 ~]# pstree
    init─┬─NetworkManager
    ├─abrtd
    ├─acpid
    ├─atd
    ├─auditd───{auditd}
    ├─automount───4*[{automount}]
    ├─bonobo-activati───{bonobo-activat}
    ├─certmonger
    ├─console-kit-dae───63*[{console-kit-da}]
    ├─crond
    ├─cupsd
    ├─2*[dbus-daemon───{dbus-daemon}]
    ├─dbus-launch
    ├─devkit-power-da
    ├─gconfd-2
    ├─gdm-binary─┬─gdm-simple-slav─┬─Xorg
    │ │ ├─gdm-session-wor
    │ │ ├─gnome-session─┬─at-spi-registry
    │ │ │ ├─gdm-simple-gree
    │ │ │ ├─gnome-power-man
    │ │ │ ├─metacity
    │ │ │ ├─plymouth-log-vi
    │ │ │ ├─polkit-gnome-au
    │ │ │ └─{gnome-session}
    │ │ └─{gdm-simple-sla}
    │ └─{gdm-binary}
    ├─gnome-settings-───{gnome-settings}
    ├─gvfsd
    ├─hald─┬─hald-runner─┬─hald-addon-acpi
    │ │ └─hald-addon-inpu
    │ └─{hald}
    ├─master─┬─pickup
    │ └─qmgr
    ├─5*[mingetty]
    ├─modem-manager
    ├─polkitd
    ├─pulseaudio───2*[{pulseaudio}]
    ├─rpc.statd
    ├─rpcbind
    ├─rsyslogd───3*[{rsyslogd}]
    ├─rtkit-daemon───2*[{rtkit-daemon}]
    ├─sshd───sshd───bash───pstree
    ├─udevd───2*[udevd]
    └─wpa_supplicant
    [root@weekend110 ~]#

      由此可见,进程是逐级创建的,因此其显得像一颗倒立的树,树最顶层的进程是init进程,即根进程。

      

      在命令后加上“&”    使进程后台运行

      ps           查看linux系统中当前哪些进程在运行

     

    每行字段为一行。

    以1848 pts/0 00:00:00 bash为例

    1848是PID,即进程ID。

    pts/0为该进程所使用的终端号

    00:00:00是该进程运行时占用CPU的时间

    bash是为启动该进程的命令,其中bash是登录系统后执行的第一条命令,而ps则是在输入ps时所执行的命令。

    [root@weekend110 ~]# ps
    PID TTY TIME CMD
    1848 pts/0 00:00:00 bash
    1893 pts/0 00:00:00 ps
    [root@weekend110 ~]#

     

    以root 1 0 0 09:10 ? 00:00:03 /sbin/init为例

    root 是UID,即运行该进程的用户

    1是PID,即进程ID

    0是PPID,即父进程ID

    0是C,即执行该进程时CPU调度的情况

    09:10是STIME,该进程的启动时间

    ?是TTY,所使用的虚拟终端号

    00:00:03是TIME,是进程所使用的CPU时间

    /sbin/init是CMD,是启动该进程的命令

    [root@weekend110 ~]# ps -ef
    UID PID PPID C STIME TTY TIME CMD
    root 1 0 0 09:10 ? 00:00:03 /sbin/init
    root 2 0 0 09:10 ? 00:00:00 [kthreadd]
    root 3 2 0 09:10 ? 00:00:00 [migration/0]
    root 4 2 0 09:10 ? 00:00:00 [ksoftirqd/0]
    root 5 2 0 09:10 ? 00:00:00 [migration/0]
    root 6 2 0 09:10 ? 00:00:00 [watchdog/0]
    root 7 2 0 09:10 ? 00:00:01 [events/0]
    root 8 2 0 09:10 ? 00:00:00 [cgroup]
    root 9 2 0 09:10 ? 00:00:00 [khelper]
    root 10 2 0 09:10 ? 00:00:00 [netns]
    root 11 2 0 09:10 ? 00:00:00 [async/mgr]
    root 12 2 0 09:10 ? 00:00:00 [pm]
    root 13 2 0 09:10 ? 00:00:00 [sync_supers]
    root 14 2 0 09:10 ? 00:00:00 [bdi-default]
    root 15 2 0 09:10 ? 00:00:00 [kintegrityd/0]
    root 16 2 0 09:10 ? 00:00:00 [kblockd/0]
    root 17 2 0 09:10 ? 00:00:00 [kacpid]
    root 18 2 0 09:10 ? 00:00:00 [kacpi_notify]
    root 19 2 0 09:10 ? 00:00:00 [kacpi_hotplug]
    root 20 2 0 09:10 ? 00:00:00 [ata_aux]
    root 21 2 0 09:10 ? 00:00:00 [ata_sff/0]
    root 22 2 0 09:10 ? 00:00:00 [ksuspend_usbd]
    root 23 2 0 09:10 ? 00:00:00 [khubd]
    root 24 2 0 09:10 ? 00:00:00 [kseriod]
    root 25 2 0 09:10 ? 00:00:00 [md/0]
    root 26 2 0 09:10 ? 00:00:00 [md_misc/0]
    root 27 2 0 09:10 ? 00:00:00 [linkwatch]
    root 28 2 0 09:10 ? 00:00:00 [khungtaskd]
    root 29 2 0 09:10 ? 00:00:00 [kswapd0]
    root 30 2 0 09:10 ? 00:00:00 [ksmd]
    root 31 2 0 09:10 ? 00:00:00 [khugepaged]
    root 32 2 0 09:10 ? 00:00:00 [aio/0]
    root 33 2 0 09:10 ? 00:00:00 [crypto/0]
    root 38 2 0 09:10 ? 00:00:00 [kthrotld/0]
    root 39 2 0 09:10 ? 00:00:00 [pciehpd]
    root 41 2 0 09:10 ? 00:00:00 [kpsmoused]
    root 42 2 0 09:10 ? 00:00:00 [usbhid_resumer]
    root 72 2 0 09:10 ? 00:00:00 [kstriped]
    root 147 2 0 09:10 ? 00:00:00 [scsi_eh_0]
    root 148 2 0 09:10 ? 00:00:00 [scsi_eh_1]
    root 155 2 0 09:10 ? 00:00:00 [mpt_poll_0]
    root 156 2 0 09:10 ? 00:00:00 [mpt/0]
    root 157 2 0 09:10 ? 00:00:00 [scsi_eh_2]
    root 279 2 0 09:10 ? 00:00:00 [flush-8:0]
    root 285 2 0 09:10 ? 00:00:00 [jbd2/sda5-8]
    root 286 2 0 09:10 ? 00:00:00 [ext4-dio-unwrit]
    root 376 1 0 09:10 ? 00:00:01 /sbin/udevd -d
    root 716 2 0 09:10 ? 00:00:00 [vmmemctl]
    root 915 2 0 09:10 ? 00:00:00 [jbd2/sda1-8]
    root 916 2 0 09:10 ? 00:00:00 [ext4-dio-unwrit]
    root 917 2 0 09:10 ? 00:00:00 [jbd2/sda2-8]
    root 918 2 0 09:10 ? 00:00:00 [ext4-dio-unwrit]
    root 1010 2 0 09:10 ? 00:00:00 [kauditd]
    root 1212 1 0 09:10 ? 00:00:00 auditd
    root 1237 1 0 09:10 ? 00:00:00 /sbin/rsyslogd -i /var/run/syslogd.pid -c 5
    rpc 1280 1 0 09:10 ? 00:00:00 rpcbind
    dbus 1295 1 0 09:10 ? 00:00:00 dbus-daemon --system
    root 1306 1 0 09:10 ? 00:00:00 NetworkManager --pid-file=/var/run/NetworkManager/NetworkManager.pid
    root 1312 1 0 09:10 ? 00:00:00 /usr/sbin/modem-manager
    rpcuser 1325 1 0 09:10 ? 00:00:00 rpc.statd
    root 1380 1 0 09:10 ? 00:00:00 /usr/sbin/wpa_supplicant -c /etc/wpa_supplicant/wpa_supplicant.conf -B -u -f /var/l
    root 1381 1 0 09:10 ? 00:00:00 cupsd -C /etc/cups/cupsd.conf
    root 1398 1 0 09:11 ? 00:00:00 /usr/sbin/acpid
    68 1407 1 0 09:11 ? 00:00:00 hald
    root 1408 1407 0 09:11 ? 00:00:00 hald-runner
    root 1450 1408 0 09:11 ? 00:00:00 hald-addon-input: Listening on /dev/input/event2 /dev/input/event0
    68 1461 1408 0 09:11 ? 00:00:00 hald-addon-acpi: listening on acpid socket /var/run/acpid.socket
    root 1481 1 0 09:11 ? 00:00:00 automount --pid-file /var/run/autofs.pid
    root 1506 1 0 09:11 ? 00:00:00 /usr/sbin/sshd
    root 1586 1 0 09:11 ? 00:00:00 /usr/libexec/postfix/master
    postfix 1594 1586 0 09:11 ? 00:00:00 pickup -l -t fifo -u
    postfix 1595 1586 0 09:11 ? 00:00:00 qmgr -l -t fifo -u
    root 1610 1 0 09:11 ? 00:00:00 /usr/sbin/abrtd
    root 1618 1 0 09:11 ? 00:00:03 crond
    root 1629 1 0 09:11 ? 00:00:00 /usr/sbin/atd
    root 1641 1 0 09:11 ? 00:00:00 /usr/sbin/certmonger -S -p /var/run/certmonger.pid
    root 1649 1 0 09:11 ? 00:00:00 /usr/sbin/gdm-binary -nodaemon
    root 1654 1 0 09:11 tty2 00:00:00 /sbin/mingetty /dev/tty2
    root 1656 1 0 09:11 tty3 00:00:00 /sbin/mingetty /dev/tty3
    root 1658 1 0 09:11 tty4 00:00:00 /sbin/mingetty /dev/tty4
    root 1660 1 0 09:11 tty5 00:00:00 /sbin/mingetty /dev/tty5
    root 1668 1 0 09:11 tty6 00:00:00 /sbin/mingetty /dev/tty6
    root 1669 376 0 09:11 ? 00:00:00 /sbin/udevd -d
    root 1670 376 0 09:11 ? 00:00:00 /sbin/udevd -d
    root 1685 1649 0 09:11 ? 00:00:00 /usr/libexec/gdm-simple-slave --display-id /org/gnome/DisplayManager/Display1 --for
    root 1688 1685 0 09:11 tty1 00:00:03 /usr/bin/Xorg :0 -nr -verbose -audit 4 -auth /var/run/gdm/auth-for-gdm-OMcqii/datab
    root 1704 1 0 09:11 ? 00:00:00 /usr/sbin/console-kit-daemon --no-daemon
    gdm 1774 1 0 09:11 ? 00:00:00 /usr/bin/dbus-launch --exit-with-session
    gdm 1775 1 0 09:11 ? 00:00:00 /bin/dbus-daemon --fork --print-pid 5 --print-address 7 --session
    gdm 1777 1685 0 09:11 ? 00:00:00 /usr/bin/gnome-session --autostart=/usr/share/gdm/autostart/LoginWindow/
    root 1780 1 0 09:11 ? 00:00:00 /usr/libexec/devkit-power-daemon
    gdm 1784 1 0 09:11 ? 00:00:00 /usr/libexec/gconfd-2
    root 1797 1506 0 09:11 ? 00:00:00 sshd: root@pts/0
    gdm 1801 1777 0 09:11 ? 00:00:00 /usr/libexec/at-spi-registryd
    gdm 1805 1 0 09:11 ? 00:00:01 /usr/libexec/gnome-settings-daemon --gconf-prefix=/apps/gdm/simple-greeter/settings
    gdm 1807 1 0 09:11 ? 00:00:00 /usr/libexec/bonobo-activation-server --ac-activate --ior-output-fd=12
    gdm 1816 1 0 09:11 ? 00:00:00 /usr/libexec/gvfsd
    gdm 1817 1777 0 09:11 ? 00:00:00 metacity
    gdm 1818 1777 0 09:11 ? 00:00:00 /usr/libexec/polkit-gnome-authentication-agent-1
    gdm 1819 1777 0 09:11 ? 00:00:00 plymouth-log-viewer --icon
    gdm 1820 1777 0 09:11 ? 00:00:00 gnome-power-manager
    gdm 1821 1777 0 09:11 ? 00:00:00 /usr/libexec/gdm-simple-greeter
    root 1824 1 0 09:11 ? 00:00:00 /usr/libexec/polkit-1/polkitd
    gdm 1833 1 0 09:11 ? 00:00:04 /usr/bin/pulseaudio --start --log-target=syslog
    rtkit 1835 1 0 09:11 ? 00:00:00 /usr/libexec/rtkit-daemon
    root 1842 1685 0 09:11 ? 00:00:00 pam: gdm-password
    root 1848 1797 0 09:12 pts/0 00:00:00 -bash
    root 1957 1848 0 09:26 pts/0 00:00:00 ps -ef
    [root@weekend110 ~]#

      ps -ef | more       更直观,利用管道传送到more中显示,使用空格键查看下一页,按q键或ctrl +c 退出

    [root@weekend110 ~]# ps -ef | more
    UID PID PPID C STIME TTY TIME CMD
    root 1 0 0 09:10 ? 00:00:03 /sbin/init
    root 2 0 0 09:10 ? 00:00:00 [kthreadd]
    root 3 2 0 09:10 ? 00:00:00 [migration/0]
    root 4 2 0 09:10 ? 00:00:00 [ksoftirqd/0]
    root 5 2 0 09:10 ? 00:00:00 [migration/0]
    root 6 2 0 09:10 ? 00:00:00 [watchdog/0]
    root 7 2 0 09:10 ? 00:00:01 [events/0]
    root 8 2 0 09:10 ? 00:00:00 [cgroup]
    root 9 2 0 09:10 ? 00:00:00 [khelper]
    root 10 2 0 09:10 ? 00:00:00 [netns]
    root 11 2 0 09:10 ? 00:00:00 [async/mgr]
    root 12 2 0 09:10 ? 00:00:00 [pm]
    root 13 2 0 09:10 ? 00:00:00 [sync_supers]
    root 14 2 0 09:10 ? 00:00:00 [bdi-default]
    root 15 2 0 09:10 ? 00:00:00 [kintegrityd/0]
    root 16 2 0 09:10 ? 00:00:00 [kblockd/0]
    root 17 2 0 09:10 ? 00:00:00 [kacpid]
    root 18 2 0 09:10 ? 00:00:00 [kacpi_notify]
    root 19 2 0 09:10 ? 00:00:00 [kacpi_hotplug]
    root 20 2 0 09:10 ? 00:00:00 [ata_aux]
    root 21 2 0 09:10 ? 00:00:00 [ata_sff/0]
    root 22 2 0 09:10 ? 00:00:00 [ksuspend_usbd]
    root 23 2 0 09:10 ? 00:00:00 [khubd]
    root 24 2 0 09:10 ? 00:00:00 [kseriod]
    root 25 2 0 09:10 ? 00:00:00 [md/0]
    root 26 2 0 09:10 ? 00:00:00 [md_misc/0]
    root 27 2 0 09:10 ? 00:00:00 [linkwatch]
    root 28 2 0 09:10 ? 00:00:00 [khungtaskd]
    root 29 2 0 09:10 ? 00:00:00 [kswapd0]
    root 30 2 0 09:10 ? 00:00:00 [ksmd]
    root 31 2 0 09:10 ? 00:00:00 [khugepaged]
    root 32 2 0 09:10 ? 00:00:00 [aio/0]
    root 33 2 0 09:10 ? 00:00:00 [crypto/0]
    root 38 2 0 09:10 ? 00:00:00 [kthrotld/0]
    root 39 2 0 09:10 ? 00:00:00 [pciehpd]

    --More--

      ps nux        查看linux系统中所有进程的资源使用情况

    以root 1 0.2 0.0 19356 1540 ? Ss 09:10 0:03 /sbin/init为例

    root是USER,是运行该进程的用户

    0.2是%CPU,是运行该进程时CPU的使用率

    0.0是%MEM,是运行进程时内存的使用率

    19356是VSZ,是进程占用虚拟内存的大小

    Ss是STAT,是进程的状态,S表示睡眠,R表示在运行

    09:10是START,是进程的启动时间

    /sbin/init是COMMAND,是启动进程的命令

    [root@weekend110 ~]# ps aux
    USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND
    root 1 0.2 0.0 19356 1540 ? Ss 09:10 0:03 /sbin/init
    root 2 0.0 0.0 0 0 ? S 09:10 0:00 [kthreadd]
    root 3 0.0 0.0 0 0 ? S 09:10 0:00 [migration/0]
    root 4 0.0 0.0 0 0 ? S 09:10 0:00 [ksoftirqd/0]
    root 5 0.0 0.0 0 0 ? S 09:10 0:00 [migration/0]
    root 6 0.0 0.0 0 0 ? S 09:10 0:00 [watchdog/0]
    root 7 0.1 0.0 0 0 ? S 09:10 0:02 [events/0]
    root 8 0.0 0.0 0 0 ? S 09:10 0:00 [cgroup]
    root 9 0.0 0.0 0 0 ? S 09:10 0:00 [khelper]
    root 10 0.0 0.0 0 0 ? S 09:10 0:00 [netns]
    root 11 0.0 0.0 0 0 ? S 09:10 0:00 [async/mgr]
    root 12 0.0 0.0 0 0 ? S 09:10 0:00 [pm]
    root 13 0.0 0.0 0 0 ? S 09:10 0:00 [sync_supers]
    root 14 0.0 0.0 0 0 ? S 09:10 0:00 [bdi-default]
    root 15 0.0 0.0 0 0 ? S 09:10 0:00 [kintegrityd/0]
    root 16 0.0 0.0 0 0 ? S 09:10 0:00 [kblockd/0]
    root 17 0.0 0.0 0 0 ? S 09:10 0:00 [kacpid]
    root 18 0.0 0.0 0 0 ? S 09:10 0:00 [kacpi_notify]
    root 19 0.0 0.0 0 0 ? S 09:10 0:00 [kacpi_hotplug]
    root 20 0.0 0.0 0 0 ? S 09:10 0:00 [ata_aux]
    root 21 0.0 0.0 0 0 ? S 09:10 0:00 [ata_sff/0]
    root 22 0.0 0.0 0 0 ? S 09:10 0:00 [ksuspend_usbd]
    root 23 0.0 0.0 0 0 ? S 09:10 0:00 [khubd]
    root 24 0.0 0.0 0 0 ? S 09:10 0:00 [kseriod]
    root 25 0.0 0.0 0 0 ? S 09:10 0:00 [md/0]
    root 26 0.0 0.0 0 0 ? S 09:10 0:00 [md_misc/0]
    root 27 0.0 0.0 0 0 ? S 09:10 0:00 [linkwatch]
    root 28 0.0 0.0 0 0 ? S 09:10 0:00 [khungtaskd]
    root 29 0.0 0.0 0 0 ? S 09:10 0:00 [kswapd0]
    root 30 0.0 0.0 0 0 ? SN 09:10 0:00 [ksmd]
    root 31 0.0 0.0 0 0 ? SN 09:10 0:00 [khugepaged]
    root 32 0.0 0.0 0 0 ? S 09:10 0:00 [aio/0]
    root 33 0.0 0.0 0 0 ? S 09:10 0:00 [crypto/0]
    root 38 0.0 0.0 0 0 ? S 09:10 0:00 [kthrotld/0]
    root 39 0.0 0.0 0 0 ? S 09:10 0:00 [pciehpd]
    root 41 0.0 0.0 0 0 ? S 09:10 0:00 [kpsmoused]
    root 42 0.0 0.0 0 0 ? S 09:10 0:00 [usbhid_resumer]
    root 72 0.0 0.0 0 0 ? S 09:10 0:00 [kstriped]
    root 147 0.0 0.0 0 0 ? S 09:10 0:00 [scsi_eh_0]
    root 148 0.0 0.0 0 0 ? S 09:10 0:00 [scsi_eh_1]
    root 155 0.0 0.0 0 0 ? S 09:10 0:00 [mpt_poll_0]
    root 156 0.0 0.0 0 0 ? S 09:10 0:00 [mpt/0]
    root 157 0.0 0.0 0 0 ? S 09:10 0:00 [scsi_eh_2]
    root 279 0.0 0.0 0 0 ? S 09:10 0:00 [flush-8:0]
    root 285 0.0 0.0 0 0 ? S 09:10 0:00 [jbd2/sda5-8]
    root 286 0.0 0.0 0 0 ? S 09:10 0:00 [ext4-dio-unwrit]
    root 376 0.1 0.0 11616 1716 ? S<s 09:10 0:01 /sbin/udevd -d
    root 716 0.0 0.0 0 0 ? S 09:10 0:00 [vmmemctl]
    root 915 0.0 0.0 0 0 ? S 09:10 0:00 [jbd2/sda1-8]
    root 916 0.0 0.0 0 0 ? S 09:10 0:00 [ext4-dio-unwrit]
    root 917 0.0 0.0 0 0 ? S 09:10 0:00 [jbd2/sda2-8]
    root 918 0.0 0.0 0 0 ? S 09:10 0:00 [ext4-dio-unwrit]
    root 1010 0.0 0.0 0 0 ? S 09:10 0:00 [kauditd]
    root 1212 0.0 0.0 27640 840 ? S<sl 09:10 0:00 auditd
    root 1237 0.0 0.0 251200 1684 ? Sl 09:10 0:00 /sbin/rsyslogd -i /var/run/syslogd.pid -c 5
    rpc 1280 0.0 0.0 18976 904 ? Ss 09:10 0:00 rpcbind
    dbus 1295 0.0 0.0 32076 1632 ? Ssl 09:10 0:00 dbus-daemon --system
    root 1306 0.0 0.2 82740 4440 ? Ss 09:10 0:00 NetworkManager --pid-file=/var/run/NetworkManager/NetworkManager.pi
    root 1312 0.0 0.1 58064 2464 ? S 09:10 0:00 /usr/sbin/modem-manager
    rpcuser 1325 0.0 0.0 23348 1372 ? Ss 09:10 0:00 rpc.statd
    root 1380 0.0 0.0 44968 696 ? Ss 09:10 0:00 /usr/sbin/wpa_supplicant -c /etc/wpa_supplicant/wpa_supplicant.conf
    root 1381 0.0 0.1 188872 3340 ? Ss 09:10 0:00 cupsd -C /etc/cups/cupsd.conf
    root 1398 0.0 0.0 4080 664 ? Ss 09:11 0:00 /usr/sbin/acpid
    68 1407 0.0 0.2 39000 5336 ? Ssl 09:11 0:00 hald
    root 1408 0.0 0.0 20328 1196 ? S 09:11 0:00 hald-runner
    root 1450 0.0 0.0 22448 1096 ? S 09:11 0:00 hald-addon-input: Listening on /dev/input/event2 /dev/input/event0
    68 1461 0.0 0.0 17936 1048 ? S 09:11 0:00 hald-addon-acpi: listening on acpid socket /var/run/acpid.socket
    root 1481 0.0 0.0 385728 1784 ? Ssl 09:11 0:00 automount --pid-file /var/run/autofs.pid
    root 1506 0.0 0.0 66140 1248 ? Ss 09:11 0:00 /usr/sbin/sshd
    root 1586 0.0 0.1 80808 3396 ? Ss 09:11 0:00 /usr/libexec/postfix/master
    postfix 1594 0.0 0.1 80888 3380 ? S 09:11 0:00 pickup -l -t fifo -u
    postfix 1595 0.0 0.1 80956 3420 ? S 09:11 0:00 qmgr -l -t fifo -u
    root 1610 0.0 0.0 110328 956 ? Ss 09:11 0:00 /usr/sbin/abrtd
    root 1618 0.2 0.0 116840 1388 ? Ss 09:11 0:03 crond
    root 1629 0.0 0.0 21076 492 ? Ss 09:11 0:00 /usr/sbin/atd
    root 1641 0.0 0.0 61864 616 ? Ss 09:11 0:00 /usr/sbin/certmonger -S -p /var/run/certmonger.pid
    root 1649 0.0 0.1 133944 2188 ? Ssl 09:11 0:00 /usr/sbin/gdm-binary -nodaemon
    root 1654 0.0 0.0 4064 540 tty2 Ss+ 09:11 0:00 /sbin/mingetty /dev/tty2
    root 1656 0.0 0.0 4064 544 tty3 Ss+ 09:11 0:00 /sbin/mingetty /dev/tty3
    root 1658 0.0 0.0 4064 544 tty4 Ss+ 09:11 0:00 /sbin/mingetty /dev/tty4
    root 1660 0.0 0.0 4064 544 tty5 Ss+ 09:11 0:00 /sbin/mingetty /dev/tty5
    root 1668 0.0 0.0 4064 540 tty6 Ss+ 09:11 0:00 /sbin/mingetty /dev/tty6
    root 1669 0.0 0.1 12536 2812 ? S< 09:11 0:00 /sbin/udevd -d
    root 1670 0.0 0.1 12536 2812 ? S< 09:11 0:00 /sbin/udevd -d
    root 1685 0.0 0.1 164576 3056 ? Sl 09:11 0:00 /usr/libexec/gdm-simple-slave --display-id /org/gnome/DisplayManage
    root 1688 0.2 1.1 151336 22768 tty1 Ss+ 09:11 0:03 /usr/bin/Xorg :0 -nr -verbose -audit 4 -auth /var/run/gdm/auth-for-
    root 1704 0.0 0.1 577596 3256 ? Sl 09:11 0:00 /usr/sbin/console-kit-daemon --no-daemon
    gdm 1774 0.0 0.0 20040 656 ? S 09:11 0:00 /usr/bin/dbus-launch --exit-with-session
    gdm 1775 0.0 0.0 31776 1288 ? Ssl 09:11 0:00 /bin/dbus-daemon --fork --print-pid 5 --print-address 7 --session
    gdm 1777 0.0 0.4 268844 7880 ? Ssl 09:11 0:00 /usr/bin/gnome-session --autostart=/usr/share/gdm/autostart/LoginWi
    root 1780 0.0 0.1 49876 2704 ? S 09:11 0:00 /usr/libexec/devkit-power-daemon
    gdm 1784 0.0 0.2 133480 5528 ? S 09:11 0:00 /usr/libexec/gconfd-2
    root 1797 0.0 0.2 99872 4000 ? Ss 09:11 0:00 sshd: root@pts/0
    gdm 1801 0.0 0.2 120392 4440 ? S 09:11 0:00 /usr/libexec/at-spi-registryd
    gdm 1805 0.1 0.6 356620 12740 ? Ssl 09:11 0:01 /usr/libexec/gnome-settings-daemon --gconf-prefix=/apps/gdm/simple-
    gdm 1807 0.0 0.1 368768 3012 ? Ssl 09:11 0:00 /usr/libexec/bonobo-activation-server --ac-activate --ior-output-fd
    gdm 1816 0.0 0.0 135180 1896 ? S 09:11 0:00 /usr/libexec/gvfsd
    gdm 1817 0.0 0.5 294708 9912 ? S 09:11 0:00 metacity
    gdm 1818 0.0 0.3 247964 7388 ? S 09:11 0:00 /usr/libexec/polkit-gnome-authentication-agent-1
    gdm 1819 0.0 0.6 295284 12264 ? S 09:11 0:00 plymouth-log-viewer --icon
    gdm 1820 0.0 0.4 273400 8652 ? S 09:11 0:00 gnome-power-manager
    gdm 1821 0.0 0.8 390244 15772 ? S 09:11 0:00 /usr/libexec/gdm-simple-greeter
    root 1824 0.0 0.2 52580 4196 ? S 09:11 0:00 /usr/libexec/polkit-1/polkitd
    gdm 1833 0.3 0.2 427152 4180 ? S<sl 09:11 0:04 /usr/bin/pulseaudio --start --log-target=syslog
    rtkit 1835 0.0 0.0 168456 1200 ? SNl 09:11 0:00 /usr/libexec/rtkit-daemon
    root 1842 0.0 0.1 141648 2076 ? S 09:11 0:00 pam: gdm-password
    root 1848 0.0 0.0 108344 1792 pts/0 Ss 09:12 0:00 -bash
    root 1975 3.0 0.0 110248 1140 pts/0 R+ 09:32 0:00 ps aux
    [root@weekend110 ~]#

      top          对linux系统进行动态监控,按q键或ctrl +c 退出

    以top - 09:39:26 up 29 min, 1 user, load average: 0.00, 0.00, 0.00为例

    top - 09:39:26 up 29 min,说的是top命令在09:39:26启动,并持续29min

    1 user,说的是系统中共有一个用户在登录

    load average: 0.00, 0.00, 0.00,说的是系统负载的平均值

    以Tasks: 108 total, 1 running, 107 sleeping, 0 stopped, 0 zombie为例

    108total,是结果显示系统中共有108个进程,目前只有1个进程正在运行,有107个进程处于睡眠状态,没有进程被终止,没有进程被僵死。

    以Cpu(s): 0.0%us, 0.0%sy, 0.0%ni,100.0%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st为例

    top显示运行在用户模式和内核模式的进程(ni)所占的CPU百分比,以及在系统空间(id)时所占的CPU空间时间百分比,wa(iowait)表示没有进程在CPU上运行时处理器等待I/O完成的时间百分比,hi和si表示硬件与软件中断所花费的CPU时间的百分比。

    以Mem: 1906552k total, 303492k used, 1603060k free, 25744k buffers为例。这里显示是系统物理内存的使用情况

    依次表示系统的总内存,已使用的内存、空闲的内存、缓冲区使用的内存

    Swap:  3128464k total,        0k used,  3128464k free,    99456k cached。这里显示是系统交换分区的信息

    依次表示交换分区的总量、使用量、空闲和用于内核缓存的内存量

    PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND 。这里显示是系统进程信息

    NI表示进程的优先级,SHR表示进程使用的共享内存的数量,TIME+表示自进程启动以来所使用的CPU时间量

    [root@weekend110 ~]# top
    top - 09:39:26 up 29 min, 1 user, load average: 0.00, 0.00, 0.00
    Tasks: 108 total, 1 running, 107 sleeping, 0 stopped, 0 zombie
    Cpu(s): 0.0%us, 0.0%sy, 0.0%ni,100.0%id, 0.0%wa, 0.0%hi, 0.0%si, 0.0%st
    Mem: 1906552k total, 303492k used, 1603060k free, 25744k buffers
    Swap:  3128464k total,        0k used,  3128464k free,    99456k cached

    PID USER PR NI VIRT RES SHR S %CPU %MEM TIME+ COMMAND
    1987 root 20 0 15036 1224 944 R 0.3 0.1 0:00.29 top
    1 root 20 0 19356 1540 1228 S 0.0 0.1 0:03.31 init
    2 root 20 0 0 0 0 S 0.0 0.0 0:00.00 kthreadd
    3 root RT 0 0 0 0 S 0.0 0.0 0:00.00 migration/0
    4 root 20 0 0 0 0 S 0.0 0.0 0:00.01 ksoftirqd/0
    5 root RT 0 0 0 0 S 0.0 0.0 0:00.00 migration/0
    6 root RT 0 0 0 0 S 0.0 0.0 0:00.02 watchdog/0
    7 root 20 0 0 0 0 S 0.0 0.0 0:02.67 events/0
    8 root 20 0 0 0 0 S 0.0 0.0 0:00.00 cgroup
    9 root 20 0 0 0 0 S 0.0 0.0 0:00.01 khelper
    10 root 20 0 0 0 0 S 0.0 0.0 0:00.00 netns
    11 root 20 0 0 0 0 S 0.0 0.0 0:00.00 async/mgr
    12 root 20 0 0 0 0 S 0.0 0.0 0:00.00 pm

      其实,除了,使用命令来监控linux系统的进程外,自带了一个图形系统监控工具。即System Monitor。在终端上输入gnome-system-monitor或Applications->System Tools->System Monitor。类似于windows系统的任务管理器。

    [root@weekend110 ~]gnome -system-monitor

     

     或者

     

     

    进程创建和终止

      对于Linux系统啊,只要输入一条指令并执行该指令,就开启了一个新的进程。可以在指令后面使用“&”来开启一个后台进程。

    什么是后台进程?

      所谓后台进程,就是进程在运行后并未显示进程执行的过程,且直接返回终端提示符、不占用终端窗口的进程。

    什么时候用后台进程?

      当执行一个比较耗时的进程且不需要用户进程交互时,可以考虑选择在后台进程该进程。

     

    [root@weekend110 ~]# top &
    [1] 2493
    [root@weekend110 ~]# ^C

    [1]+ Stopped top
    [root@weekend110 ~]#

       进程的终止,使用kill命令将其终止,而在使用kill之前,需要知道该进程ID,即PID,可以使用ps命令。

    如下,演示

     

    [root@weekend110 ~]# man ls      运行man命令
    LS(1) User Commands LS(1)

    NAME
    ls - list directory contents

    SYNOPSIS
    ls [OPTION]... [FILE]...

    DESCRIPTION
    List information about the FILEs (the current directory by default). Sort entries alphabetically if none of
    -cftuvSUX nor --sort.

    Mandatory arguments to long options are mandatory for short options too.

    -a, --all
    do not ignore entries starting with .

    -A, --almost-all
    do not list implied . and ..

    --author

    [root@weekend110 ~]# pgrep -l man      使用pgrep来获取处于运行状态的man命令的PID

    2542 man

    kill -1       挂起

    kill -2       终端

    kill -9  终止

    kill -15  终止

    kill -19  暂停

    也可,在图形界面里,对进程的终止。

  • 相关阅读:
    destoon-手机版商铺中视频打开提示请登录查看,登录之后还是提示
    destoon-开启远程ftp后会员头像上传不显示
    destoon-手机版会员公司主页首页调用商城信息
    destoon-列表页调用分类属性
    destoon-供应列表调用分类属性值
    destoon会员公司主页扫描二维码手机上显示空白
    destoon-7.0资讯开启内容显示上一篇下一篇不显示
    destoon-使用手机号注册会员名提示“会员登录名已经被注册”的限制去掉
    destoon配置微信提示48001
    destoon-7.0手机版腾讯视频不显示
  • 原文地址:https://www.cnblogs.com/zlslch/p/5980322.html
Copyright © 2011-2022 走看看