Ariyan
Ariyan

Reputation: 15158

C: Multiple forks

I need to use shared memory and fork to do this:
Multipling random 512x512 matrixes using 4 processes and shared memory.
I know how to fork one child but
How can I fork 4 processes that do 1/4 of work?

Thanks

Upvotes: 0

Views: 482

Answers (3)

John
John

Reputation: 299

How about this: Read the chapter in your textbook again, ask your classmates for the notes you missed, attack your TA while he or she is sneaking out of his office, then ask your professor during their office hours!

Upvotes: 1

Borealid
Borealid

Reputation: 98469

ct = 0;
while (ct < 3 && fork() == 0) {
    ct++;
}

ct will tell you which thread you are. You should probably check for a return of -1 from fork(), though.

Upvotes: 3

Jens Gustedt
Jens Gustedt

Reputation: 78903

Why don't you just fork three times in a row?

Upvotes: 0

Related Questions