玩瞳科技运维面试题(部分)
问题九:
随意写文件命令?怎么向屏幕输出带空格的字符串,比如“hello world”?
vi
[root@vultr ~]# echo "hello world"
hello world
问题十七:
Linux中进程有哪几种状态?在ps显示出来的信息中,分别用什么符号表示?
[引自维基百科]
S:代表进程的状态
分别为:
随意写文件命令?怎么向屏幕输出带空格的字符串,比如“hello world”?
vi
[root@vultr ~]# echo "hello world"
hello world
问题十七:
Linux中进程有哪几种状态?在ps显示出来的信息中,分别用什么符号表示?
[引自维基百科]
Process states[edit source]
An operating system kernel that allows multitasking needs processes to have certain states. Names for these states are not standardized, but they have similar functionality.
- First, the process is "created" by being loaded from a secondary storage device (hard disk drive, CD-ROM, etc.) into main memory. After that, the process scheduler assigns it to the "waiting" state.
- While the process is "waiting", it waits for the scheduler to do a so-called context switch and load the process into the processor. The process state then becomes "running", and the processor executes the process instructions.
- If a process needs to wait for a resource (wait for user input or file to open, for example), it is assigned the "blocked" state. The process state is changed back to "waiting" when the process no longer needs to wait (in a blocked state).
- Once the process finishes execution, or is terminated by the operating system, it is no longer needed. The process is removed instantly or is moved to the "terminated" state. When removed, it just waits to be removed from main memory.
S:代表进程的状态
分别为:
- R(Running)
- S(Sleep)
- D
- T(terminated)
- Z(zombie):进程已中止,但无法删除到内存外。
- D uninterruptible sleep (usually IO)
- R running or runnable (on run queue)
- S interruptible sleep (waiting for an event to complete)
- T stopped by job control signal
- t stopped by debugger during the tracing
- W paging (not valid since the 2.6.xx kernel)
- X dead (should never be seen)
- Z defunct ("zombie") process, terminated but not reaped by its parent
补充:
在 Linux 中,进程可以处于多种不同的状态,反映了进程当前正在做什么或者等待什么。当使用 ps 命令查看进程信息时,状态通常会显示在一个名为 STAT 或 S 的列中,并用一个或多个字符来表示。
以下是 Linux 进程的主要状态及其在 ps 输出中常见的符号表示:
主要状态:
-
运行 (Running): 进程正在 CPU 上执行,或者已经准备好立即运行。
- 符号:
R
- 符号:
-
睡眠 (Sleeping): 进程正在等待某个事件发生(例如,等待 I/O 操作完成,等待另一个进程发送信号,或者等待某个资源可用)。
- 符号:
S(Interruptible sleep): 进程可以被信号中断。这是最常见的睡眠状态。D(Uninterruptible sleep): 进程正在等待一个通常是硬件操作的 I/O 完成,并且不能被信号中断。这种状态通常出现在进程正在等待磁盘 I/O 或网络 I/O 的情况下。如果进程长时间处于D状态,可能表明存在 I/O 问题。
- 符号:
-
停止 (Stopped): 进程由于接收到某个信号(例如
SIGSTOP,SIGTSTP,SIGTTOU,SIGTTIN)而暂停执行。进程可以随后通过SIGCONT信号恢复执行。- 符号:
T
- 符号:
-
僵尸 (Zombie): 进程已经结束执行,但是其父进程还没有调用
wait()或waitpid()等系统调用来获取它的退出状态信息。僵尸进程不消耗 CPU 资源,但仍然占用进程表中的一个条目。如果系统中存在大量的僵尸进程,可能表明父进程没有正确地清理子进程。- 符号:
Z
- 符号:
其他可能出现的修饰符符号 (通常会附加在主要状态符号后面):
<(Low priority): 进程具有较低的优先级(nice 值大于 0)。N(High priority): 进程具有较高的优先级(nice 值小于 0)。s(Session leader): 进程是会话的领导者。+(Foreground process group): 进程属于前台进程组。l(Multi-threaded): 进程是多线程的。W(Swapping out): 进程正在被交换到磁盘。L(Has pages locked into memory): 进程的某些页面被锁定在内存中,不会被交换出去。t(Tracing stop): 进程被跟踪(例如,被调试器gdb或strace跟踪)。
在 ps 输出中查看状态:
当你运行 ps 命令时,通常会使用一些选项来获取更详细的信息。例如:
ps aux: 显示所有用户的详细进程信息。ps -ef: 显示系统上所有进程的完整格式信息。
在这些输出中,你会找到 STAT 或 S 列,其中包含了进程的状态符号。例如,你可能会看到像 R, S, D, T, Z, Sl, S<, SN 等组合。
记住: ps 命令的不同版本和不同的 Linux 发行版可能会在状态符号的含义和显示上略有差异,但上述是最常见和核心的状态表示。查阅你的系统上 ps 命令的 man 手册 (man ps) 可以获取最准确和详细的信息。
评论
发表评论