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

  • 毛琳淇
  • 201821121007
  • 计算1811

1. 实验环境介绍

  • 操作系统:Windows10
  • 平台:Cygwin
  • 用户名:maolinqi

 

2. 常用命令使用

 

 

 

3. 剖析ps命令

1man ps

使用方法:

SYNOPSIS

       ps [−aA] [−defl] [−g grouplist] [−G grouplist]

           [−n namelist] [−o format]... [−p proclist] [−t termlist]

           [−u userlist] [−U userlist]

参数:

 The following options shall be supported:

 

       −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.

2ps -ef

返回结果:

     UID     PID    PPID  TTY        STIME COMMAND

maolinqi     329       1 ?        18:31:43 /usr/bin/mintty

maolinqi     339     330 pty0     18:32:48 /usr/bin/ps

maolinqi     330     329 pty0     18:31:44 /usr/bin/bash

参数的含义:

e:显示所有进程。

f:显示用户ID、父进程ID、最近CPU使用情况和进程时间等等。

每个字段的含义

UID用户ID 

PID进程ID

PPID父进程ID

C进程占用CPU的百分比

STIME进程启动到现在的时间

TTY终端的次要装置号码

TIMECPU运行时间

CMD:命令的名字

(3)ps -aux

执行结果:

 PID    PPID    PGID     WINPID   TTY         UID    STIME COMMAND

     1070    1069    1070       7528  pty0      197609 19:02:16 /usr/bin/bash

     1082    1070    1082      11408  pty0      197609 19:05:16 /usr/bin/ps

     1069       1    1069      17928  ?         197609 19:02:11 /usr/bin/mintty

参数含义:

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

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

x:显示所有程序

字段含义:

COMMAND:命令的名字

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

(1)修改用户名时找不到etc/passwd文件

解:使用mkpasswd -l > /etc/passwd把windows的用户导入到cygwin下。根据搜索到的博客改用户名。

(2)执行命令ps -aux时出现ps: user x unknown

解:百度发现"ps -aux"打印用户名为"x"的用户的所有进程,以及打印所有将由-a选项选择的过程。如果用户名为"x"不存在,ps的将会解释为"ps aux",而且会打印一个警告所以要使用ps aux。

posted @ 2020-03-05 19:35  my7in7i  阅读(130)  评论(0编辑  收藏  举报