Unix - 关于&和ps

时间:2012-06-13 02:34:47

标签: c unix 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的最佳方法是什么?我只是在这里寻找指导,这只是硬件任务的一小部分。我已经完成了主要的事情!

2 个答案:

答案 0 :(得分:4)

./fork_demo &
ps

说明:

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

答案 1 :(得分:3)

ps -ef | grep fork_demo

ps aux | grep fork_demo

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