linux - Forking vs Threading -


i have used threading before in applications , know concepts well, in operating system lecture came across fork(). similar threading.

i google searched difference between them , came know that:

  1. fork nothing new process looks old or parent process still different process different process id , having it’s own memory.
  2. threads light-weight process have less overhead

but, there still questions in mind.

  1. when should prefer fork() on threading , vice-verse?
  2. if want call external application child, should use fork() or threads it?
  3. while doing google search found people saying bad thing call fork() inside thread. why people want call fork() inside thread when similar things?
  4. is true fork() cannot take advantage of multiprocessor system because parent , child process don't run simultaneously?

thanx!!

the main difference between forking , threading approaches 1 of operating system architecture. in days when unix designed, forking easy, simple system answered mainframe , server type requirements best, such popularized on nix systems. when ms rearchitected nt kernel scratch, focused more on threading model. such there today still notable difference nix systems being efficient forking, , windows more efficient threads. can notably see in apache uses prefork strategy on nix, , threadpooling on windows.

specifically questions:

when should prefer fork() on threading , vice-verse?

on nix system you're doing far more complex task instantiating worker, or want implicit security sandboxing of separate processes.

if want call external application child, should use fork() or threads it?

if child identical task parent, identical code, use fork. smaller subtasks use threads. separate external processes use neither, call them proper api calls.

while doing google search found people saying bad thing call fork() inside thread. why people want call fork() inside thread when similar things?

not entirely sure think it's computationally rather expensive duplicate process , lot of subthreads.

is true fork() cannot take advantage of multiprocessor system because parent , child process don't run simultaneously?

this false, fork creates new process takes advantage of features available processes in os task scheduler.


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -