+在c++进程状态下的含义



我制作了test.cpp并编译了这个。

int main() {
while(1);
}

g++ test.cpp

ps -aux | grep a.out.

进程状态a.out为R+

是的。当然,进程是无限运行的。

但是,我不理解+

ps手册中+在前台进程组

我不知道a.out在前台进程组是什么意思

PROCESS STATE CODES         
Here are the different values that the s, stat and state output
specifiers (header "STAT" or "S") will display to describe the
state of a process:
D    uninterruptible sleep (usually IO)
I    Idle kernel thread
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
For BSD formats and when the stat keyword is used, additional
characters may be displayed:
<    high-priority (not nice to other users)
N    low-priority (nice to other users)
L    has pages locked into memory (for real-time and
custom IO)
s    is a session leader
l    is multi-threaded (using CLONE_THREAD, like NPTL
pthreads do)
+    is in the foreground process group

这基本上意味着进程在终端会话中执行,占用它,用户直接访问它。后台进程运行时没有直接的用户交互。主要用于想要继续使用终端会话,但又需要运行时间要求高的计算时。

您可以通过在启动命令后提供&符号来更改程序的这种状态:

./a.out &

然后您可以使用fg命令或将进程置于后台后获得的进程id来恢复进程。

最新更新