九幽ir

导航

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

  • 姓名:万大明
  • 学号:201821121058
  • 班级:计算1812

1. 实验环境介绍

  • 操作系统:Microsoft Windows 版本 1903(OS 内部版本 18362.657)
  • 平台:Cygwin
  • 用户名:wandaming

 

 

 

2. 常用命令使用

 简单使用 ls -ls,pwd,man,help几个命令,如下(help命令截取部分):

 

 

 

3. 剖析ps命令

  运行man ps

PROLOG

This manual page is part of the POSIX Programmer's Manual. The Linux implementation of this interface may differ (consult the corresponding Linux manual page
for details of Linux behavior), or the interface may not be implemented on Linux.

NAME
ps — report process status

SYNOPSIS
ps [−aA] [−defl] [−g grouplist] [−G grouplist]
[−n namelist] [−o format]... [−p proclist] [−t termlist]
[−u userlist] [−U userlist]

DESCRIPTION
The ps utility shall write information about processes, subject to having appropriate privileges to obtain information about those processes.

By default, ps shall select all processes with the same effective user ID as the current user and the same controlling terminal as the invoker.

OPTIONS
The ps utility shall conform to the Base Definitions volume of POSIX.1‐2008, Section 12.2, Utility Syntax Guidelines.

The following options shall be supported:

−a Write information for all processes associated with terminals. Implementations may omit session leaders from this list.

−A Write information for all processes.

−d Write information for all processes, except session leaders.

−e Write information for all processes. (Equivalent to −A.)

−f Generate a full listing. (See the STDOUT section for the contents of a full listing.)

−g grouplist
Write information for processes whose session leaders are given in grouplist. The application shall ensure that the grouplist is a single argument in
the form of a <blank> or <comma>-separated list.

−G grouplist
Write information for processes whose real group ID numbers are given in grouplist. The application shall ensure that the grouplist is a single ar‐
gument in the form of a <blank> or <comma>-separated list.

−l Generate a long listing. (See STDOUT for the contents of a long listing.)

−n namelist
Specify the name of an alternative system namelist file in place of the default. The name of the default file and the format of a namelist file are
unspecified.

−o format Write information according to the format specification given in format. This is fully described in the STDOUT section. Multiple −o options can be
specified; the format specification shall be interpreted as the <space>-separated concatenation of all the format option-arguments.

−p proclist
Write information for processes whose process ID numbers are given in proclist. The application shall ensure that the proclist is a single argument
in the form of a <blank> or <comma>-separated list.

−t termlist
Write information for processes associated with terminals given in termlist. The application shall ensure that the termlist is a single argument in
the form of a <blank> or <comma>-separated list. Terminal identifiers shall be given in an implementation-defined format. On XSI-conformant systems,
they shall be given in one of two forms: the device's filename (for example, tty04) or, if the device's filename starts with tty, just the identifier
following the characters tty (for example, "04").

−u userlist
Write information for processes whose user ID numbers or login names are given in userlist. The application shall ensure that the userlist is a sin‐
gle argument in the form of a <blank> or <comma>-separated list. In the listing, the numerical user ID shall be written unless the −f option is used,
in which case the login name shall be written.

运行命令"ps -ef"的返回结果:

 

 

 

 运行命令"ps aux"的返回结果:

 

 

 

 解释命令中参数的含义:

      -e : 显示所有进程信息。

      -f :使用完整的(full)格式显示进程信息

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

  UID :启动该进程的用户ID号。

  PID :进程ID号。

  PPID :该进程的父进程ID号。

  PGID :进程组ID。

  C :CPU使用的资源百分比。

  STIME :进程启动时间。

  WINPID :windows下的pid。

  TTY :启动进程的终端名。

  TIME :该进程使用CPU的累计时间。

  COMMAND :进程所运行的命令。

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

 1、改名问题:改用户名时先在cygwin中输入命令“mkpasswd  > /etc/passwd”,可在cygwin/etc目录下出现passwd文件,用文本编辑

      器将最后一行的系统默认名改成自己名字,再在home文件中删除默认用户名文件即可,不需要创建新文件,因为在你

      运行cygwin是会自动在home目录下自动创建一个以你设置的用户名为文件名的文件,我的是“wandaming”。

      注:“>”前面有空格后面无空格

             

 2、问题:在运行“man ps ”指令时,出现“没有ps的手册页条目”。

                  

       解决:到网站 https://mirrors.edge.kernel.org/pub/linux/docs/man-pages/ 下载man-pages-posix手册,将下载好的压缩包解

                  压缩到文件usr/share下,把原本的man文件删掉,将下载的文件改为man即可,命令men ps运行如下(截取部分):

 

 

 3、ps -aux与"ps aux"区别:POSIX和UNIX的标准要求"ps -aux"打印用户名为"x"的用户的所有进程,以及打印所有将由-a选项选择的过程。如果用户名为"x"

      不存在,ps的将会解释为"ps aux",而且会打印一个警告。这种行为是为了帮助转换旧脚本 和习惯。它是脆弱的,即将更改,因

      此不应依赖。

 4、运行"ps aux"时每次所得值不同,查阅百度解释为每次的CPU占用率可能不同。

 

posted on 2020-03-07 13:27  我不是酸柠檬与醋  阅读(174)  评论(0编辑  收藏  举报