Jordan
Jordan

Reputation: 2140

Unix - regarding & and ps

I'm working on a hw assignment and was wondering if someone with a bit more Unix experience could explain what is meant by the following question:

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.

Sample program 1 is:

#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>

int
main()
{
    puts("Before fork");
    fork();
    sleep(10);
    puts("After fork");
}

I compiled and ran:

./fork_demo &

What is the best way to use ps with this running in background? I'm only looking for guidance here and this is a tiny portion of a HW assignment. I've already done the major stuff!

Upvotes: 0

Views: 127

Answers (2)

xelco52
xelco52

Reputation: 5347

ps -ef | grep fork_demo

or

ps aux | grep fork_demo

Not knowing which are the "right parameters" for your assignment, I took some guesses.

Upvotes: 3

Brendan Long
Brendan Long

Reputation: 54242

./fork_demo &
ps

Explanation:

& forces the process before it (fork_demo) into the background. At that point, you can run another command (like ps).

Upvotes: 4

Related Questions