代码改变世界

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

2020-03-05 20:38  Wangpj  阅读(156)  评论(0编辑  收藏  举报

姓名:王丕杰

学号:201821121052

班级:计算1812

1.实验环境介绍

操作系统:Window10(版本:18363.657)

平台:Cygwin

用户名:wangpijie

2. 常用命令使用

举例如下:

3. 剖析ps命令

(1)ps使用方法及参数

SYNOPSIS
       ps [−aA] [−defl] [−g grouplist] [−G grouplist]
           [−n namelist] [−o format]... [−p proclist] [−t termlist]
           [−u userlist] [−U userlist]
       −a        Write  information  for all processes associated with termi‐
                 nals.  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 argument 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 specifica‐
                 tion shall be interpreted as the <space>-separated  concate‐
                 nation 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 sys‐
                 tems,  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 lo‐
                 gin  names are given in userlist.  The application shall en‐
                 sure that the userlist is a single argument in the form of  a
                 <blank>  or  <comma>-separated list. In the listing, the nu‐
                 merical user ID shall be written  unless  the  −f  option  is
                 used, in which case the login name shall be written.

       −U userlist
                 Write information for processes whose real user ID numbers or
                 login names are given in  userlist.   The  application  shall
                 ensure  that the userlist is a single argument in the form of
                 a <blank> or <comma>-separated list.

       With the exception of −f, −l, −n namelist, and −o format,  all  of  the
       options  shown  are used to select processes. If any are specified, the
       default list shall be ignored and ps shall select the processes repre‐
       sented by the inclusive OR of all the selection-criteria options.

(2)运行并解释ps命令参数

①运行ps命令,结果如下:

$ ps
      PID    PPID    PGID     WINPID   TTY         UID    STIME COMMAND
     1451    1450    1451       8932  pty0      197609 19:58:09 /usr/bin/bash
     1473    1451    1473      12360  pty0      197609 20:13:59 /usr/bin/ps
     1450       1    1450      11656  ?         197609 19:58:07 /usr/bin/mintty

②运行ps -ef 命令,结果如下:

$ ps -ef
     UID     PID    PPID  TTY        STIME COMMAND
wangpiji    1474    1451 pty0     20:15:18 /usr/bin/ps
wangpiji    1451    1450 pty0     19:58:09 /usr/bin/bash
wangpiji    1450       1 ?        19:58:07 /usr/bin/mintty

 参数含义:

e :表示显示全部进程

f  :表示完整-格式,包括命令行

③运行ps aux 命令,结果如下:

$ ps aux
      PID    PPID    PGID     WINPID   TTY         UID    STIME COMMAND
     1451    1450    1451       8932  pty0      197609 19:58:09 /usr/bin/bash
     1450       1    1450      11656  ?         197609 19:58:07 /usr/bin/mintty
     1475    1451    1475      19468  pty0      197609 20:16:54 /usr/bin/ps

参数含义:

a :显示现行终端机下的所有程序,包括其他用户的程序

u :以用户为主的格式来显示程序状况

x : 显示所有程序,不以终端机来区分

(3)字段含义

UID:用户ID

PID:进程ID

PPID:父进程ID

PGID:进程组ID

TTY:终端的次要装置号码

STIME:进程开始时间

COMMAND:所执行的指令