fork on multiple cpu server

S

sc_wizard29

Hi everyone,

One of my collegue at work said that on a 4 CPU server, it's better to
write a program that forks 4 "sub-processes" instead of writing a
single process program (ie : a program that doesn't call fork())

I guess the theory behind this is that each one of the 4 sub-processes
can be processed by a separate CPU, which means that in a ideal
scenario, 4 instructions can be processed "at the same time".

What is your opinion on this ?
 
J

Jens Thoms Toerring

One of my collegue at work said that on a 4 CPU server, it's better to
write a program that forks 4 "sub-processes" instead of writing a
single process program (ie : a program that doesn't call fork())
I guess the theory behind this is that each one of the 4 sub-processes
can be processed by a separate CPU, which means that in a ideal
scenario, 4 instructions can be processed "at the same time".

While your collegue might be right, this is the wrong place for
a discussion since it doesn't got anyhing to do with C, which is
the topic of this group (and the C standard doesn't even consider
that there could be more than one program running at a time). Per-
haps you should ask in a UNIX group (e.g. comp.unix.programmer)
since fork() historically came form UNIX (if I am not completely
mistaken) or in comp.programming, where all kinds of questions
related to programming get discussed.

Regards, Jens
 
R

Richard Tobin

One of my collegue at work said that on a 4 CPU server, it's better to
write a program that forks 4 "sub-processes" instead of writing a
single process program (ie : a program that doesn't call fork())

I guess the theory behind this is that each one of the 4 sub-processes
can be processed by a separate CPU, which means that in a ideal
scenario, 4 instructions can be processed "at the same time".

This is reasonable if your program can be decomposed into parts that
can be run simultaneously, without much need to communicate. If they
need to share data, you may find it easier to use multiple threads
inside a single program. How you do this depends on your system;
C itself does not include any thread mechanism.

Bear in mind that other people using the server may be annoyed at your
making full use of it...

-- Richard
 
S

sc_wizard29

Well, I guess you're right but since it was in the context of a C
program... well, never mind : thanks for answering !
 
R

Richard

Hi everyone,

One of my collegue at work said that on a 4 CPU server, it's better to
write a program that forks 4 "sub-processes" instead of writing a
single process program (ie : a program that doesn't call fork())

I guess the theory behind this is that each one of the 4 sub-processes
can be processed by a separate CPU, which means that in a ideal
scenario, 4 instructions can be processed "at the same time".

What is your opinion on this ?

Look up Amdahl's law.

http://en.wikipedia.org/wiki/Amdahl's_law

It is discussed in this great book:

http://www.amazon.com/Programming-POSIX-Threads-David-Butenhof/dp/0201633922
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top