views:

161

answers:

1

Hi... I have a project for my college but unfortunately, I struggle in programming, apart from simple C programs. Anyway, the way I see it, I think the code I need should be around 20-30 lines, so if somebody can provide me some help I'll be really grateful. Here is the project:

  • A parent process will produce 10 random integer numbers (rand).

  • Then the parent process will produce (fork) 2 child processes.

  • The child processes will print their PID (getpid) and will sort (qsort, as ) the integer numbers, one in ascending order and the other in descending order.

  • The sorted tables will be printed to stdout with the use of write.

  • The parent process will standby (waitpid) until the child processes finish their execution.

+2  A: 

You've basically described what you need to do, which is important. What I would do next is write it out in pseudocode so you can visually see what you need to do. Something like:

Array of int data = generateData
Create child(data)
Create child(data)
 Wait for children

Then specify it more detailed:

int[] data = generateData();
int pid = fork();
if (isChild(pid))
    DoChildStuff(data);
else
    int nextpid = fork();
    if (isChild(pid))
        DoOtherChildStuff(data);
    else
        DoParentStuff()

I've intentionally left the important parts undefined (isChild isn't a real call etc.) So that you can learn what the homework wants you to, but this should get you on the right path if you have your lecture notes.

Matt
thanx man... yeah I think I can handle it now according to my notes
Agios