OS第1次实验报告:熟悉使用Linux命令和剖析ps命令

  • 姓名:巫艳珍
  • 学号:201821121034
  • 班级:计算1812

1. 实验环境介绍

实验环境:

  • 操作系统:Ubuntu 16.04 LTS
  • 平台:双操作系统

用户名:wuyanzhen

2. 常用命令使用

  • 查看当前目录ls
  • 进入特权模式sudo su
  • 新建文件mkdir

 

3. 剖析ps命令

(1)运行man ps,将ps使用方法拷贝过来,比如:

PS(1)                                                                                        User Commands                                                                                       PS(1)

NAME
       ps - report a snapshot of the current processes.

SYNOPSIS
       ps [options]

DESCRIPTION
       ps displays information about a selection of the active processes.  If you want a repetitive update of the selection and the displayed information, use top(1) instead.
  • ps命令的参数:
SIMPLE PROCESS SELECTION
       a      Lift the BSD-style "only yourself" restriction, which is imposed upon the set of all processes when some BSD-style (without "-") options are used or when the ps personality setting is
              BSD-like.  The set of processes selected in this manner is in addition to the set of processes selected by other means.  An alternate description is that this option causes ps to list
              all processes with a terminal (tty), or to list all processes when used together with the x option.

       -A     Select all processes.  Identical to -e.

       -a     Select all processes except both session leaders (see getsid(2)) and processes not associated with a terminal.

       -d     Select all processes except session leaders.

       --deselect
              Select all processes except those that fulfill the specified conditions (negates the selection).  Identical to -N.

       -e     Select all processes.  Identical to -A.

       g      Really all, even session leaders.  This flag is obsolete and may be discontinued in a future release.  It is normally implied by the a flag, and is only useful when operating in the
              sunos4 personality.

       -N     Select all processes except those that fulfill the specified conditions (negates the selection).  Identical to --deselect.

       T      Select all processes associated with this terminal.  Identical to the t option without any argument.

       r      Restrict the selection to only running processes.

       x      Lift the BSD-style "must have a tty" restriction, which is imposed upon the set of all processes when some BSD-style (without "-") options are used or when the ps personality setting
              is BSD-like.  The set of processes selected in this manner is in addition to the set of processes selected by other means.  An alternate description is that this option causes ps to
              list all processes owned by you (same EUID as ps), or to list all processes when used together with the a option.

PROCESS SELECTION BY LIST
       These options accept a single argument in the form of a blank-separated or comma-separated list.  They can be used multiple times.  For example: ps -p "1 2" -p 3,4

       -123   Identical to --pid 123.

       123    Identical to --pid 123.

       -C cmdlist
              Select by command name.  This selects the processes whose executable name is given in cmdlist.

       -G grplist
              Select by real group ID (RGID) or name.  This selects the processes whose real group name or ID is in the grplist list.  The real group ID identifies the group of the user who created
              the process, see getgid(2).

       -g grplist
              Select by session OR by effective group name.  Selection by session is specified by many standards, but selection by effective group is the logical behavior that several other
              operating systems use.  This ps will select by session when the list is completely numeric (as sessions are).  Group ID numbers will work only when some group names are also specified.
              See the -s and --group options.

       --Group grplist
              Select by real group ID (RGID) or name.  Identical to -G.

       --group grplist
              Select by effective group ID (EGID) or name.  This selects the processes whose effective group name or ID is in grplist.  The effective group ID describes the group whose file access
              permissions are used by the process (see getegid(2)).  The -g option is often an alternative to --group.

       p pidlist
              Select by process ID.  Identical to -p and --pid.

       -p pidlist
              Select by PID.  This selects the processes whose process ID numbers appear in pidlist.  Identical to p and --pid.

       --pid pidlist
              Select by process ID.  Identical to -p and p.

              Select by process ID.  Identical to -p and p.

       --ppid pidlist
              Select by parent process ID.  This selects the processes with a parent process ID in pidlist.  That is, it selects processes that are children of those listed in pidlist.

       q pidlist
              Select by process ID (quick mode).  Identical to -q and --quick-pid.

       -q pidlist
              Select by PID (quick mode).  This selects the processes whose process ID numbers appear in pidlist.  With this option ps reads the necessary info only for the pids listed in the
              pidlist and doesn't apply additional filtering rules. The order of pids is unsorted and preserved. No additional selection options, sorting and forest type listings are allowed in this
              mode.  Identical to q and --quick-pid.

       --quick-pid pidlist
              Select by process ID (quick mode).  Identical to -q and q.

       -s sesslist
              Select by session ID.  This selects the processes with a session ID specified in sesslist.

       --sid sesslist
              Select by session ID.  Identical to -s.

       t ttylist
              Select by tty.  Nearly identical to -t and --tty, but can also be used with an empty ttylist to indicate the terminal associated with ps.  Using the T option is considered cleaner than
              using t with an empty ttylist.

       -t ttylist
              Select by tty.  This selects the processes associated with the terminals given in ttylist.  Terminals (ttys, or screens for text output) can be specified in several forms: /dev/ttyS1,
              ttyS1, S1.  A plain "-" may be used to select processes not attached to any terminal.

       --tty ttylist
              Select by terminal.  Identical to -t and t.

       U userlist
              Select by effective user ID (EUID) or name.  This selects the processes whose effective user name or ID is in userlist.  The effective user ID describes the user whose file access
              permissions are used by the process (see geteuid(2)).  Identical to -u and --user.

       -U userlist
              Select by real user ID (RUID) or name.  It selects the processes whose real user name or ID is in the userlist list.  The real user ID identifies the user who created the process, see
              getuid(2).

       -u userlist
              Select by effective user ID (EUID) or name.  This selects the processes whose effective user name or ID is in userlist.

              The effective user ID describes the user whose file access permissions are used by the process (see geteuid(2)).  Identical to U and --user.

       --User userlist
              Select by real user ID (RUID) or name.  Identical to -U.

       --user userlist
              Select by effective user ID (EUID) or name.  Identical to -u and U.

(2)ps命令有很多参数,运行命令ps -ef,得出系统的返回结果如下(部分结果):

UID        PID  PPID  C STIME TTY          TIME CMD
root         1     0  0 07:00 ?        00:00:02 /sbin/init
root         2     0  0 07:00 ?        00:00:00 [kthreadd]
root         4     2  0 07:00 ?        00:00:00 [kworker/0:0H]
root         6     2  0 07:00 ?        00:00:00 [mm_percpu_wq]
root         7     2  0 07:00 ?        00:00:00 [ksoftirqd/0]
root         8     2  0 07:00 ?        00:00:00 [rcu_sched]
root         9     2  0 07:00 ?        00:00:00 [rcu_bh]
root        10     2  0 07:00 ?        00:00:00 [migration/0]
root        11     2  0 07:00 ?        00:00:00 [watchdog/0]
root        12     2  0 07:00 ?        00:00:00 [cpuhp/0]
root        13     2  0 07:00 ?        00:00:00 [cpuhp/1]
root        14     2  0 07:00 ?        00:00:00 [watchdog/1]
root        15     2  0 07:00 ?        00:00:00 [migration/1]
root        16     2  0 07:00 ?        00:00:00 [ksoftirqd/1]
root        18     2  0 07:00 ?        00:00:00 [kworker/1:0H]
root        19     2  0 07:00 ?        00:00:00 [cpuhp/2]
root        20     2  0 07:00 ?        00:00:00 [watchdog/2]
  • 命令中参数的含义

  ps -ef表示查看全格式的全部进程

  -e:显示所有进程

  -f:以完整的格式显示

  • 解释返回结果每个字段的含义

  UID:UserId,表示用户ID,每个用户有一个唯一的UID

  PID:(进程控制符)进程ID,操作系统每打开一个程序,就会创建一个进程ID

  PPID:当前进程的父进程ID

  C:表示CPU 使用的资源百分比

  STIME:start  time,进程的启动时间

  TTY:与进程关联的终端(tty),若与终端机无关,则显示 “?”

  TIME:进程实际使用 CPU 运作的时间

  CMD:该进程运行的命令

(3)运行命令ps -aux,得出系统的执行结果如下(部分结果):

USER       PID %CPU %MEM    VSZ   RSS TTY      STAT START   TIME COMMAND
root         1  0.0  0.0 185436  5932 ?        Ss   07:00   0:02 /sbin/init
root         2  0.0  0.0      0     0 ?        S    07:00   0:00 [kthreadd]
root         4  0.0  0.0      0     0 ?        I<   07:00   0:00 [kworker/0:0H]
root         6  0.0  0.0      0     0 ?        I<   07:00   0:00 [mm_percpu_wq]
root         7  0.0  0.0      0     0 ?        S    07:00   0:00 [ksoftirqd/0]
root         8  0.0  0.0      0     0 ?        I    07:00   0:00 [rcu_sched]
root         9  0.0  0.0      0     0 ?        I    07:00   0:00 [rcu_bh]
root        10  0.0  0.0      0     0 ?        S    07:00   0:00 [migration/0]
root        11  0.0  0.0      0     0 ?        S    07:00   0:00 [watchdog/0]
root        12  0.0  0.0      0     0 ?        S    07:00   0:00 [cpuhp/0]
root        13  0.0  0.0      0     0 ?        S    07:00   0:00 [cpuhp/1]
root        14  0.0  0.0      0     0 ?        S    07:00   0:00 [watchdog/1]
root        15  0.0  0.0      0     0 ?        S    07:00   0:00 [migration/1]
root        16  0.0  0.0      0     0 ?        S    07:00   0:00 [ksoftirqd/1]
root        18  0.0  0.0      0     0 ?        I<   07:00   0:00 [kworker/1:0H]
root        19  0.0  0.0      0     0 ?        S    07:00   0:00 [cpuhp/2]
root        20  0.0  0.0      0     0 ?        S    07:00   0:00 [watchdog/2]
  • 命令中参数的含义

  -a:显示同一终端下的所有程序

  -u: 指定用户的所有进程

  -aux:显示所有包含其他使用者的行程 

  • 解释返回结果每个字段的含义(前面解释过的参数不再解释)

  USER:表示进程所属的使用者

  %CPU:表示该进程使用掉的CPU资源百分比

  %MEM:表示该进程占用的物理内存百分比

  VSZ:表示当前进程使用掉的虚拟内存量

  RSS:表示当前进程使用掉的固定内存量

  STAT:该程序目前的状态

  主要有:

    R:该程序正在运作,或可被运作

    S:该程序在睡眠当中,可被某些讯号唤醒

    T:该程序目前正在侦测或停止了

    Z:该程序应该已经终止,但是其父程序无法正常终止它,造成zombie (疆尸) 程序的状态

  START:表示该进程被触发启动的时间

  COMMAND:表示该程序的实际指令

4. 通过该实验产生新的疑问及解答

(1)在修改ubuntu用户名时遇到困难

  • 解答:最初用老师给的方法,没能修改成功,后来,在网上找了很多方法,发现需要先修改密码再修改用户名。

  可参考链接:https://cloud.tencent.com/developer/article/1415383

  但这个方法可能还存在问题,修改了用户名之后发现每次进系统时输入密码之后,进入界面比之前慢。

(2)由于对ubuntu系统不够了解,截图使用出现小问题

  • 上网查找截图的方法,发现可以利用键盘上的shift+prt sc sysrq进行截图

 

posted @ 2020-03-05 23:17  王尔  阅读(215)  评论(0编辑  收藏  举报