c语言 - Unix - about & and ps



我正在做一个硬件作业,想知道是否有人有更多的Unix经验可以解释以下问题的含义:

Run sample program 1 in the background with &
Using the ps utility with appropriate options, observe and report the PIDs and the status  of your processes.

示例程序 1 是:

#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
int
main()
{
    puts("Before fork");
    fork();
    sleep(10);
    puts("After fork");
}

我编译并运行:

./fork_demo &

在后台运行时使用ps的最佳方法是什么?我只是在这里寻找指导,这只是硬件作业的一小部分。我已经完成了主要的事情!

./fork_demo &
ps

解释:

&强制它(fork_demo)进入后台的进程。此时,您可以运行另一个命令(如 ps )。

ps -ef | grep fork_demo

ps aux | grep fork_demo

不知道哪些是你的作业的"正确参数",我做了一些猜测。

最新更新