OS第1次实验报告:熟悉使用Linux命令和剖析ps命令
姓名:蒋浩天
学号:201821121024
班级:计算1811
1.实验环境介绍
- 操作系统:Ubuntu 18.04.3 LTS
- 平台:双操作系统
2. 常用命令使用
3. 剖析ps命令
运行man ps
,将ps
使用方法拷贝过来
SYNOPSIS ps [options] EXAMPLES To see every process on the system using standard syntax: ps -e ps -ef ps -eF ps -ely To see every process on the system using BSD syntax: ps ax ps axu To print a process tree: ps -ejH ps axjf To get info about threads: ps -eLf ps axms To get security info: ps -eo euser,ruser,suser,fuser,f,comm,label ps axZ ps -eM To see every process running as root (real & effective ID) in user format: ps -U root -u root u To see every process with a user-defined format: ps -eo pid,tid,class,rtprio,ni,pri,psr,pcpu,stat,wchan:14,comm ps axo stat,euid,ruid,tty,tpgid,sess,pgrp,ppid,pid,pcpu,comm ps -Ao pid,tt,user,fname,tmout,f,wchan Print only the process IDs of syslogd: ps -C syslogd -o pid= Print only the name of PID 42: ps -q 42 -o comm= SIMPLE PROCESS SELECTION a Lift the BSD-style "only yourself" restriction, which is imposed upon the set of all processes when some BSD-style (without "-") options are used or when the ps personality setting is BSD-like. The set of processes selected in this manner is in addition to the set of processes selected by other means. An alternate description is that this option causes ps to list all processes with a terminal (tty), or to list all processes when used together with the x option. -A Select all processes. Identical to -e. -a Select all processes except both session leaders (see getsid(2)) and processes not associated with a terminal. -d Select all processes except session leaders. --deselect Select all processes except those that fulfill the specified conditions (negates the selection). Identical to -N. -e Select all processes. Identical to -A. g Really all, even session leaders. This flag is obsolete and may be discontinued in a future release. It is normally implied by the a flag, and is only useful when operating in the sunos4 personality. -N Select all processes except those that fulfill the specified conditions (negates the selection). Identical to --deselect. T Select all processes associated with this terminal. Identical to the t option without any argument. r Restrict the selection to only running processes. x Lift the BSD-style "must have a tty" restriction, which is imposed upon the set of all processes when some BSD-style (without "-") options are used or when the ps personality setting is BSD-like. The set of processes selected in this manner is in addition to the set of processes selected by other means. An alternate description is that this option causes ps to list all processes owned by you (same EUID as ps), or to list all processes when used together with the a option. PROCESS SELECTION BY LIST These options accept a single argument in the form of a blank-separated or comma-separated list. They can be used multiple times. For example: ps -p "1 2" -p 3,4 -123 Identical to --pid 123. 123 Identical to --pid 123. -C cmdlist Select by command name. This selects the processes whose executable name is given in cmdlist. -G grplist Select by real group ID (RGID) or name. This selects the processes whose real group name or ID is in the grplist list. The real group ID identifies the group of the user who created the process, see getgid(2). -g grplist Select by session OR by effective group name. Selection by session is specified by many standards, but selection by effective group is the logical behavior that several other operating systems use. This ps will select by session when the list is completely numeric (as sessions are). Group ID numbers will work only when some group names are also specified. See the -s and --group options. --Group grplist Select by real group ID (RGID) or name. Identical to -G. --group grplist Select by effective group ID (EGID) or name. This selects the processes whose effective group name or ID is in grplist. The effective group ID describes the group whose file access permissions are used by the process (see getegid(2)). The -g option is often an alternative to --group. p pidlist Select by process ID. Identical to -p and --pid. -p pidlist Select by PID. This selects the processes whose process ID numbers appear in pidlist. Identical to p and --pid. --pid pidlist Select by process ID. Identical to -p and p. --ppid pidlist Select by parent process ID. This selects the processes with a parent process ID in pidlist. That is, it selects processes that are children of those listed in pidlist. q pidlist Select by process ID (quick mode). Identical to -q and --quick-pid. -q pidlist Select by PID (quick mode). This selects the processes whose process ID numbers appear in pidlist. With this option ps reads the necessary info only for the pids listed in the pidlist and doesn't apply additional filtering rules. The order of pids is unsorted and preserved. No additional selection options, sorting and forest type listings are allowed in this mode. Identical to q and --quick-pid. --quick-pid pidlist Select by process ID (quick mode). Identical to -q and q. -s sesslist Select by session ID. This selects the processes with a session ID specified in sesslist. --sid sesslist Select by session ID. Identical to -s. t ttylist Select by tty. Nearly identical to -t and --tty, but can also be used with an empty ttylist to indicate the terminal associated with ps. Using the T option is considered cleaner than using t with an empty ttylist. -t ttylist Select by tty. This selects the processes associated with the terminals given in ttylist. Terminals (ttys, or screens for text output) can be specified in several forms: /dev/ttyS1, ttyS1, S1. A plain "-" may be used to select processes not attached to any terminal. --tty ttylist Select by terminal. Identical to -t and t. U userlist Select by effective user ID (EUID) or name. This selects the processes whose effective user name or ID is in userlist. The effective user ID describes the user whose file access permissions are used by the process (see geteuid(2)). Identical to -u and --user. -U userlist Select by real user ID (RUID) or name. It selects the processes whose real user name or ID is in the userlist list. The real user ID identifies the user who created the process, see getuid(2). -u userlist Select by effective user ID (EUID) or name. This selects the processes whose effective user name or ID is in userlist. The effective user ID describes the user whose file access --User userlist Select by real user ID (RUID) or name. Identical to -U. --user userlist Select by effective user ID (EUID) or name. Identical to -u and U.
运行
ps -ef
结果(部分):
UID PID PPID C STIME TTY TIME CMD root 1 0 0 20:40 ? 00:00:00 /sbin/init splash root 2 0 0 20:40 ? 00:00:00 [kthreadd] root 3 2 0 20:40 ? 00:00:00 [rcu_gp] root 4 2 0 20:40 ? 00:00:00 [rcu_par_gp] root 6 2 0 20:40 ? 00:00:00 [kworker/0:0H-kb] root 8 2 0 20:40 ? 00:00:00 [mm_percpu_wq] root 9 2 0 20:40 ? 00:00:00 [ksoftirqd/0] root 10 2 0 20:40 ? 00:00:00 [rcu_sched]
-a:显示系统运行的所有进程,包括其他用户的进程,不管是后台进程,还是与终端无关的进程或者是会话进程。
-f:f表示full,表示做一个更为完整的输出。
UID:代表执行者身份,用户ID。
PID:代表进程的ID号。
PPID:代表父进程的ID号。
C:代表cpu使用的资源百分比。
STIME:代表系统时间。
TTY:代表该进程是在哪个终端机上面运作的,若与终端机无关则显示“?”。tty1-tty6是本机上面的登入者程序,若为pts/0等等,则表示为由网络连接进主机的程序。
TIME:表示使用掉的cpu时间。
CMD:表示所下达的指令名称。
运行
ps -aux
结果(部分):
USER PID %CPU %MEM VSZ RSS TTY STAT START TIME COMMAND root 1 0.0 0.0 225452 9152 ? Ss 20:40 0:00 /sbin/init spla root 2 0.0 0.0 0 0 ? S 20:40 0:00 [kthreadd] root 3 0.0 0.0 0 0 ? I< 20:40 0:00 [rcu_gp] root 4 0.0 0.0 0 0 ? I< 20:40 0:00 [rcu_par_gp] root 6 0.0 0.0 0 0 ? I< 20:40 0:00 [kworker/0:0H-k root 8 0.0 0.0 0 0 ? I< 20:40 0:00 [mm_percpu_wq] root 9 0.0 0.0 0 0 ? S 20:40 0:00 [ksoftirqd/0] root 10 0.0 0.0 0 0 ? I 20:40 0:01 [rcu_sched] root 11 0.0 0.0 0 0 ? S 20:40 0:00 [migration/0] root 12 0.0 0.0 0 0 ? S 20:40 0:00 [idle_inject/0] root 14 0.0 0.0 0 0 ? S 20:40 0:00 [cpuhp/0] root 15 0.0 0.0 0 0 ? S 20:40 0:00 [cpuhp/1] root 16 0.0 0.0 0 0 ? S 20:40 0:00 [idle_inject/1] root 17 0.0 0.0 0 0 ? S 20:40 0:00 [migration/1] root 18 0.0 0.0 0 0 ? S 20:40 0:00 [ksoftirqd/1] root 20 0.0 0.0 0 0 ? I< 20:40 0:00 [kworker/1:0H-k root 21 0.0 0.0 0 0 ? S 20:40 0:00 [cpuhp/2] root 22 0.0 0.0 0 0 ? S 20:40 0:00 [idle_inject/2] root 23 0.0 0.0 0 0 ? S 20:40 0:00 [migration/2] root 24 0.0 0.0 0 0 ? S 20:40 0:00 [ksoftirqd/2] root 26 0.0 0.0 0 0 ? I< 20:40 0:00 [kworker/2:0H-k root 27 0.0 0.0 0 0 ? S 20:40 0:00 [cpuhp/3] root 28 0.0 0.0 0 0 ? S 20:40 0:00 [idle_inject/3] root 29 0.0 0.0 0 0 ? S 20:40 0:00 [migration/3] root 30 0.0 0.0 0 0 ? S 20:40 0:00 [ksoftirqd/3] root 32 0.0 0.0 0 0 ? I< 20:40 0:00 [kworker/3:0H-k root 33 0.0 0.0 0 0 ? S 20:40 0:00 [cpuhp/4] root 34 0.0 0.0 0 0 ? S 20:40 0:00 [idle_inject/4] root 35 0.0 0.0 0 0 ? S 20:40 0:00 [migration/4] root 36 0.0 0.0 0 0 ? S 20:40 0:00 [ksoftirqd/4] root 38 0.0 0.0 0 0 ? I< 20:40 0:00 [kworker/4:0H-k root 39 0.0 0.0 0 0 ? S 20:40 0:00 [cpuhp/5] root 40 0.0 0.0 0 0 ? S 20:40 0:00 [idle_inject/5] root 41 0.0 0.0 0 0 ? S 20:40 0:00 [migration/5] root 42 0.0 0.0 0 0 ? S 20:40 0:00 [ksoftirqd/5] root 44 0.0 0.0 0 0 ? I< 20:40 0:00 [kworker/5:0H-k root 45 0.0 0.0 0 0 ? S 20:40 0:00 [kdevtmpfs] root 46 0.0 0.0 0 0 ? I< 20:40 0:00 [netns] root 47 0.0 0.0 0 0 ? S 20:40 0:00 [rcu_tasks_kthr root 48 0.0 0.0 0 0 ? S 20:40 0:00 [kauditd] root 49 0.0 0.0 0 0 ? I 20:40 0:00 [kworker/2:1-mm root 50 0.0 0.0 0 0 ? I 20:40 0:01 [kworker/3:1-ev root 51 0.0 0.0 0 0 ? S 20:40 0:00 [khungtaskd] root 52 0.0 0.0 0 0 ? S 20:40 0:00 [oom_reaper] root 53 0.0 0.0 0 0 ? I< 20:40 0:00 [writeback] root 54 0.0 0.0 0 0 ? S 20:40 0:00 [kcompactd0] root 55 0.0 0.0 0 0 ? SN 20:40 0:00 [ksmd] root 56 0.0 0.0 0 0 ? SN 20:40 0:00 [khugepaged] root 57 0.0 0.0 0 0 ? I< 20:40 0:00 [crypto] root 58 0.0 0.0 0 0 ? I< 20:40 0:00 [kintegrityd] root 59 0.0 0.0 0 0 ? I< 20:40 0:00 [kblockd] root 60 0.0 0.0 0 0 ? I 20:40 0:00 [kworker/5:1-ev root 61 0.0 0.0 0 0 ? I< 20:40 0:00 [tpm_dev_wq] root 62 0.0 0.0 0 0 ? I< 20:40 0:00 [ata_sff] root 63 0.0 0.0 0 0 ? I< 20:40 0:00 [md] root 64 0.0 0.0 0 0 ? I< 20:40 0:00 [edac-poller] root 65 0.0 0.0 0 0 ? I< 20:40 0:00 [devfreq_wq] root 66 0.0 0.0 0 0 ? S 20:40 0:00 [watchdogd] root 70 0.0 0.0 0 0 ? S 20:40 0:00 [kswapd0] root 71 0.0 0.0 0 0 ? I< 20:40 0:00 [kworker/u13:0- root 72 0.0 0.0 0 0 ? S 20:40 0:00 [ecryptfs-kthre root 94 0.0 0.0 0 0 ? I 20:40 0:00 [kworker/1:1-ev root 163 0.0 0.0 0 0 ? I< 20:40 0:00 [kthrotld] root 164 0.0 0.0 0 0 ? S 20:40 0:00 [irq/122-aerdrv root 165 0.0 0.0 0 0 ? S 20:40 0:00 [irq/123-aerdrv root 166 0.0 0.0 0 0 ? I< 20:40 0:00 [acpi_thermal_p root 167 0.0 0.0 0 0 ? I< 20:40 0:00 [ipv6_addrconf] root 178 0.0 0.0 0 0 ? I< 20:40 0:00 [kstrp] root 197 0.0 0.0 0 0 ? I< 20:40 0:00 [charger_manage root 217 0.0 0.0 0 0 ? I 20:40 0:00 [kworker/3:2-ev root 253 0.0 0.0 0 0 ? S 20:40 0:00 [scsi_eh_0] root 254 0.0 0.0 0 0 ? I< 20:40 0:00 [scsi_tmf_0] root 255 0.0 0.0 0 0 ? S 20:40 0:00 [scsi_eh_1] root 256 0.0 0.0 0 0 ? I< 20:40 0:00 [scsi_tmf_1] root 257 0.0 0.0 0 0 ? S 20:40 0:00 [scsi_eh_2] root 258 0.0 0.0 0 0 ? I< 20:40 0:00 [scsi_tmf_2] root 259 0.0 0.0 0 0 ? S 20:40 0:00 [scsi_eh_3] root 260 0.0 0.0 0 0 ? I< 20:40 0:00 [scsi_tmf_3] root 261 0.0 0.0 0 0 ? S 20:40 0:00 [scsi_eh_4] root 262 0.0 0.0 0 0 ? I< 20:40 0:00 [scsi_tmf_4] root 268 0.0 0.0 0 0 ? I 20:40 0:00 [kworker/0:2-ev root 269 0.0 0.0 0 0 ? I< 20:40 0:00 [kworker/5:1H-k root 296 0.0 0.0 0 0 ? I< 20:40 0:00 [kworker/2:1H-k root 298 0.0 0.0 0 0 ? I< 20:40 0:00 [kworker/0:1H-k root 299 0.0 0.0 0 0 ? S 20:40 0:00 [jbd2/sdb5-8] root 300 0.0 0.0 0 0 ? I< 20:40 0:00 [ext4-rsv-conve root 301 0.0 0.0 0 0 ? I< 20:40 0:00 [kworker/1:1H-k root 308 0.0 0.0 0 0 ? I< 20:40 0:00 [kworker/4:1H-k root 316 0.0 0.0 0 0 ? I< 20:40 0:00 [kworker/3:1H-k root 345 0.0 0.0 94924 16256 ? S<s 20:40 0:00 /lib/systemd/sy root 363 0.0 0.0 47808 6112 ? Ss 20:40 0:00 /lib/systemd/sy root 409 0.0 0.0 0 0 ? S 20:40 0:00 [irq/128-mei_me root 414 0.0 0.0 0 0 ? I 20:40 0:00 [kworker/5:2-mm root 418 0.0 0.0 0 0 ? I< 20:40 0:00 [cfg80211] root 434 0.0 0.0 0 0 ? S 20:40 0:01 [irq/129-iwlwif root 468 0.0 0.0 0 0 ? I 20:40 0:00 [kworker/0:4-cg root 479 0.0 0.0 0 0 ? I< 20:40 0:00 [kworker/u13:1- root 482 0.0 0.0 0 0 ? I< 20:40 0:00 [kmemstick] root 528 0.0 0.0 0 0 ? S 20:40 0:00 [i915/signal:0] root 529 0.0 0.0 0 0 ? S 20:40 0:00 [i915/signal:1] root 530 0.0 0.0 0 0 ? S 20:40 0:00 [i915/signal:2] root 531 0.0 0.0 0 0 ? S 20:40 0:00 [i915/signal:6] root 556 0.0 0.0 0 0 ? S 20:40 0:00 [nvidia-modeset root 659 0.0 0.0 0 0 ? S 20:40 0:00 [UVM global que root 660 0.0 0.0 0 0 ? S 20:40 0:00 [UVM Tools Even systemd+ 669 0.0 0.0 143984 3288 ? Ssl 20:40 0:00 /lib/systemd/sy systemd+ 671 0.0 0.0 70876 6080 ? Ss 20:40 0:00 /lib/systemd/sy root 748 0.0 0.0 38888 3156 ? Ss 20:40 0:00 /usr/sbin/cron root 749 0.0 0.0 4548 896 ? Ss 20:40 0:00 /usr/sbin/acpid root 751 0.0 0.0 187452 9380 ? Ssl 20:40 0:00 /usr/sbin/therm root 754 0.0 0.0 517824 13440 ? Ssl 20:40 0:00 /usr/lib/udisks root 756 0.0 0.0 108676 8596 ? Ss 20:40 0:00 /usr/sbin/cupsd root 760 0.0 0.0 309260 8944 ? Ssl 20:40 0:00 /usr/lib/accoun root 762 0.0 0.0 110480 3448 ? Ssl 20:40 0:00 /usr/sbin/irqba root 765 0.0 0.0 36536 4436 ? Ss 20:40 0:00 /usr/lib/blueto message+ 767 0.0 0.0 51368 5732 ? Ss 20:40 0:00 /usr/bin/dbus-d root 784 0.0 0.0 434320 9564 ? Ssl 20:40 0:00 /usr/sbin/Modem root 785 0.0 0.1 178096 17208 ? Ssl 20:40 0:00 /usr/bin/python root 786 0.0 0.1 503816 19416 ? Ssl 20:40 0:01 /usr/sbin/Netwo root 787 0.0 0.0 70676 6072 ? Ss 20:40 0:00 /lib/systemd/sy avahi 789 0.0 0.0 47256 3220 ? Ss 20:40 0:00 avahi-daemon: r avahi 807 0.0 0.0 47072 340 ? S 20:40 0:00 avahi-daemon: c root 809 0.0 0.0 45624 7664 ? Ss 20:40 0:00 /sbin/wpa_suppl syslog 810 0.0 0.0 263032 4664 ? Ssl 20:40 0:00 /usr/sbin/rsysl root 822 0.0 0.0 303520 10904 ? Ssl 20:40 0:00 /usr/sbin/cups- root 843 0.0 0.0 322240 11944 ? Ssl 20:40 0:00 /usr/lib/policy root 919 0.0 0.1 194792 20124 ? Ssl 20:40 0:00 /usr/bin/python root 927 0.0 0.0 308824 9120 ? SLsl 20:40 0:00 /usr/sbin/light root 934 4.4 0.6 538896 106032 tty7 Ssl+ 20:40 2:42 /usr/lib/xorg/X root 936 0.0 0.0 23748 1960 tty1 S
-u:表示以用户为主的进程状态。
x:常与a这个参数一起使用,可以列出比较完整的信息。
USER:该进程属于哪个使用者帐号。
%CPU:该进程使用掉的CPU资源百分比。
%MEM:该进程所占用的物理内存百分比。
VSZ:该进程所使用掉的虚拟内存量。
RSS:该进程占用的固定内存量。
STAT:该程序目前的状态。
START:该进程被触发启动的时间。
COMMAND:该程序的实际指令。
4. 通过该实验产生新的疑问及解答
我的系统是在很久以前配好的,所以要按照老师要求修改用户名。在使用老师提供的方法无果后,又在网上找了几种方法,无外乎新建新用户,删除原用户。因为想要使用原来系统的软件,我选择了一个折中的方法,只修改主机名。主机名存在某文件中,通过指令(在特权模式前提下) vim /etc/hostname 用vim编辑器打开该文件,将原主机名修改为现主机名,保存退出。再通过指令 vim /etc/hosts 修改该配置文件(可选)。重启之后,主机名就修改成功了。