- 李微微
- 201821121001
- 计算1811
1. 实验环境介绍
- 操作系统:Microsoft Windows [版本 10.0.18362.657]
- 平台:Cygwin
- 用户名:liweiwei:
附:Cygwin修改用户名方法
- 执行如下命令:$mkpasswd -l>/etc/passwd,创建passwd文件。
-
修改/etc/passwd文件倒数第四行(根据实际情况灵活应变)中的三个当前用户名,修改完如下:
liweiwei:*:197609:197121:U-DESKTOP-L6KA0MN\liweiwei,S-1-5-21-136635150-459745460-3400899972-1001:/home/liweiwei:/bin/bash - 修改完,保存,重启Cygwin即可。
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]
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 grou‐ plist 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 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 pro‐ clist 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 single 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. −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.
(2)运行并解释ps命令参数:
①直接运行ps,显示当前系统进程信息,相当于windows中的任务管理器,系统返回结果如下:
$ ps PID PPID PGID WINPID TTY UID STIME COMMAND 2040 1 2040 8004 ? 197609 13:41:18 /usr/bin/mintty 2084 2041 2084 21620 pty0 197609 14:09:44 /usr/bin/ps 2041 2040 2041 21224 pty0 197609 13:41:18 /usr/bin/bash
②运行命令ps -ef,系统返回结果如下:
$ ps -ef UID PID PPID TTY STIME COMMAND liweiwei 2040 1 ? 13:41:18 /usr/bin/mintty liweiwei 2041 2040 pty0 13:41:18 /usr/bin/bash liweiwei 2085 2041 pty0 14:14:33 /usr/bin/ps
参数-e能够显示用户的所有进程;
参数-f能够显示进程的UID、PID和STIME。
③运行命令ps aux,系统返回结果如下:
$ ps aux PID PPID PGID WINPID TTY UID STIME COMMAND 2101 2041 2101 23508 pty0 197609 15:09:50 /usr/bin/ps 2040 1 2040 8004 ? 197609 13:41:18 /usr/bin/mintty 2041 2040 2041 21224 pty0 197609 13:41:18 /usr/bin/bash
参数a显示现行终端机下的所有程序,包括其他用户的程序;
参数u以用户为主的格式来显示程序状况;
参数x显示所有程序,不以终端机来区分。
④运行命令ps -aW,显示windows下的进程信息,系统返回结果部分如下:
$ ps -aW PID PPID PGID WINPID TTY UID STIME COMMAND 65540 0 0 4 ? 0 Feb 15 System 65656 0 0 120 ? 0 Feb 15 Registry 65956 0 0 420 ? 0 Feb 15 C:\Windows\System32\smss.exe 66140 0 0 604 ? 0 Feb 15 C:\Windows\System32\csrss.exe 66240 0 0 704 ? 0 Feb 15 C:\Windows\System32\wininit.exe 66248 0 0 712 ? 0 Feb 15 C:\Windows\System32\csrss.exe 66312 0 0 776 ? 0 Feb 15 C:\Windows\System32\services.exe 66332 0 0 796 ? 0 Feb 15 C:\Windows\System32\lsass.exe 66444 0 0 908 ? 0 Feb 15 C:\Windows\System32\svchost.exe 66468 0 0 932 ? 0 Feb 15 C:\Windows\System32\svchost.exe 66492 0 0 956 ? 0 Feb 15 C:\Windows\System32\WUDFHost.exe 66528 0 0 992 ? 0 Feb 15 C:\Windows\System32\fontdrvhost.exe 66048 0 0 512 ? 0 Feb 15 C:\Windows\System32\svchost.exe 66388 0 0 852 ? 0 Feb 15 C:\Windows\System32\svchost.exe 66580 0 0 1044 ? 0 Feb 15 C:\Windows\System32\winlogon.exe 66640 0 0 1104 ? 0 Feb 15 C:\Windows\System32\fontdrvhost.exe 66720 0 0 1184 ? 0 Feb 15 C:\Windows\System32\dwm.exe 66740 0 0 1204 ? 0 Feb 15 C:\Windows\System32\svchost.exe 66820 0 0 1284 ? 0 Feb 15 C:\Windows\System32\svchost.exe 66828 0 0 1292 ? 0 Feb 15 C:\Windows\System32\svchost.exe 66940 0 0 1404 ? 0 Feb 15 C:\Windows\System32\svchost.exe 67020 0 0 1484 ? 0 Feb 15 C:\Windows\System32\svchost.exe 67172 0 0 1636 ? 0 Feb 15 C:\Windows\System32\svchost.exe 67204 0 0 1668 ? 0 Feb 15 C:\Windows\System32\svchost.exe 67220 0 0 1684 ? 0 Feb 15 C:\Program Files\NVIDIA Corporation\Display.NvContainer\NVDisplay.Container.exe 67272 0 0 1736 ? 0 Feb 15 C:\Windows\System32\svchost.exe 67348 0 0 1812 ? 0 Feb 15 C:\Windows\System32\svchost.exe 67424 0 0 1888 ? 0 Feb 15 C:\Windows\System32\svchost.exe 67456 0 0 1920 ? 0 Feb 15 C:\Windows\System32\svchost.exe
参数-W显示窗口和cygwin进程。
⑤运行命令ps Nt,系统返回结果如下:
$ ps Nt PID PPID PGID WINPID TTY UID STIME COMMAND 930 929 930 20528 pty0 197609 15:24:27 /usr/bin/bash 946 930 946 20724 pty0 197609 15:39:09 /usr/bin/ps 929 1 929 13756 ? 197609 15:24:27 /usr/bin/mintty
参数-N显示所有的程序,除了执行ps指令终端机下的程序之外。
参数-t指定终端机编号,并列出属于该终端机的程序的状况。
⑤运行命令ps defl,系统返回结果如下:
$ ps defl PID PPID PGID WINPID TTY UID STIME COMMAND 1471 1470 1471 16200 pty0 197609 16:38:44 /usr/bin/bash 1489 1471 1489 10196 pty0 197609 17:46:04 /usr/bin/ps 1470 1 1470 22340 ? 197609 16:38:44 /usr/bin/mintty
参数-d为所有流程编写信息,会话负责人除外。
参数-l较详细地显示该PID的信息。
(3)解释返回结果中的字段:
UID(User ID):用户ID;
PID(Process ID):进程ID;
PPID(Parent process ID):父进程ID;
C:CPU使用的资源百分比;
STIME:系统启动时间;
PGID(Process Group ID):进程组ID号;
TTY(TeleTYpe):终端的次要装置号码;
TIME:使用的CPU时间;
CMD:所下达的指令。
4. 通过该实验产生新的疑问及解答
(1)问题:在本次实验刚开始时就遇到不会修改用户名的问题。
解决:网上的方法大都是直接进入cygwin/etc文件夹,找到passwd文件打开进行修改,但是我并没有找到该文件。
于是通过重新搜索,得知可以通过命令$mkpasswd -l>/etc/passwd,创建passwd文件后修改。
(2)问题:在运行man ps命令时,出现“没有 ps 的手册页条目”的错误提示,尝试网上教程中安装man手册也没有解决,甚至导致其他man手册都不能使用。
解决:后来通过重新安装Cygwin中有关man的包解决。
(3)疑问:为什么在Cygwin中只能使用ps aux?而使用ps -aux时会报错?
解答:ps -aux,其实这种用法是错误的,应该使用ps aux和ps -fe。
man ps的第一页有一段话:
请注意"ps -aux"不同于"ps aux"。POSIX和UNIX的标准要求"ps -aux"打印用户名为"x"的用户的所有进程,
以及打印所有将由-a选项选择的过程。如果用户名为"x"不存在,ps的将会解释为"ps aux",而且会打印一个警告。
这种行为是为了帮助转换旧脚本和习惯。它是脆弱的,即将更改,因此不应依赖。
(转自《关于ps -aux的错误用法》—https://www.cnblogs.com/children/archive/2012/06/13/2548436.html)