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

  • 姓名:薛洪财
  • 学号:201821121042
  • 班级:计算1812

1. 实验环境介绍

实验环境:

  • 操作系统:Windows 10家庭中文版64位(10.0, 版本18362)
  • 平台: Cygwin64
  • 用户名:Xuehongcai

 

2. 常用命令使用

ls -ls

ls -a

man

 

help

3. 剖析ps命令

(1)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 pro‐
cesses.

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

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

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

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

    ①输入ps命令,出现以下结果:

Xuehongcai@LAPTOP-NI6PHTCT ~
$ ps
      PID    PPID    PGID     WINPID   TTY         UID    STIME COMMAND
      852       1     852       8248  ?         197609 16:27:56 /usr/bin/mintty
      873     853     873       7104  pty0      197609 16:41:16 /usr/bin/ps
      853     852     853       4392  pty0      197609 16:27:57 /usr/bin/bash

每个字段的含义

UID:User ID,即用户ID 。

PID:Process ID,即进程ID。

PPID: Parent process ID,即父进程ID。

STIME:进程启动到现在的时间。

TTY:Terminal,硬件终端的次要装置号码。

COMMAND:所执行命令的名字。

   ②输入ps -ef命令:

Xuehongcai@LAPTOP-NI6PHTCT ~
$ ps -ef
     UID     PID    PPID  TTY        STIME COMMAND
Xuehongc     852       1 ?        16:27:56 /usr/bin/mintty
Xuehongc     874     853 pty0     16:42:10 /usr/bin/ps
Xuehongc     853     852 pty0     16:27:57 /usr/bin/bash

 参数的含义:

 参数-e:显示用户的所有程序;
 参数-f:用ASCII字符显示树状结构,表达程序间的相互关系。

 ③输入ps aux:

Xuehongcai@LAPTOP-NI6PHTCT ~
$ ps aux
      PID    PPID    PGID     WINPID   TTY         UID    STIME COMMAND
      852       1     852       8248  ?         197609 16:27:56 /usr/bin/mintty
      876     853     876       8716  pty0      197609 16:44:42 /usr/bin/ps
      853     852     853       4392  pty0      197609 16:27:57 /usr/bin/bash

参数含义:

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

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

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

每个字段的含义:(不含以上已解释的参数)

PGID:Process group ID,即进程组ID。

WINPID:windows自定义进程号。

输入ps tree:

Xuehongcai@LAPTOP-NI6PHTCT ~
$ ps tree
      PID    PPID    PGID     WINPID   TTY         UID    STIME COMMAND
      852       1     852       8248  ?         197609 16:27:56 /usr/bin/mintty
      881     853     881       6896  pty0      197609 18:07:57 /usr/bin/ps
      853     852     853       4392  pty0      197609 16:27:57 /usr/bin/bash

参数含义:以树状图显示进程间的关系。

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

①输入同样的命令ps两次,为何有些pid的值会发生变化?

答:pid是被操作系统加载到内存成为进程后动态分配的资源,标识符的值是系统在它启动的时候临时分配的,每次程序执行的时候都会重新加载。 

②为什么linux的有些命令会用到"-"符号,而有的不用?

答:很多命令程序的命令行参数以“-”开头,比如ls -l, 这样是详细列出当前目录,而不是列出以-l为名的文件,这便于区分文件名还是参数。

 
posted @ 2020-03-06 18:16  ccz秋夜  阅读(230)  评论(0编辑  收藏  举报