What are the advantages of fork on unix systems?

Asked by abdullah farhat

What is the difference from a simple start **** & gt; / dev / null & amp;?

Answers

joann bubonic paulek
Nothing. This is simply an outdated concept that persists for compatibility. Single Unix Specification says the following:
There are two reasons why POSIX programmers call fork (). It was a program that was in the process of creating a new process; the program is running. In the latter case, it was followed by the exec functions.
That is, literally, there are two uses for fork: creating a new process from a new binary and creating a new “thread” in the current process. In both cases, it has flaws derived from the fork principle itself:
1) When creating a process, the address space is copied first (not the memory, but the address space - each process has its own way anyway), descriptors and other resources to immediately free them (this problem is partially solved by vfork)
2) When creating a stream, the address space is again copied instead of playing in the same one.

The only useful thing that comes to my mind is the creation of a-la Chrome / IE7 sandboxes. Creating a new process of copying the old will be a couple of million (a few milliseconds on modern processors) cycles cheaper - for those who are important to create sandboxes in huge quantities (and for whatever reason, the prefork pool of such sandboxes is not suitable) this may be significant. < br />
There is another problem besides the relatively small performance degradation in the two most frequently used scenarios. This is how the same SUS describes the problem:
There are two alternatives. Copy to all new threads. It was suspended for the new process. It calls for you to fork (). This creates a state of the art of resources. It’s not up to now that the process has taken place.

In modern software design there is such a rather important concept as link. So, the traditional unix process has low connectivity. It is simultaneously a container of resources (to simplify, we can say that it is an abstraction of memory) and a unit of execution (processor abstraction).
Posix threads are designed to solve this problem, but they are incompatible with fork. So it is better to use the approach described in the same SUS:
It is a program that has been defined as the multi-threaded program. It’s a function to undefine yourself.
Use FORK ONLY to execute a new program, use pthread_create for everything else.
duyenngoc auth
I could be wrong, but in my opinion the & quot; **** & gt; / dev / null && quot; will receive a SIGHUP if the terminal is broken
Replies:
is absolutely true! - stephanie wilga
only not HUP but bonal TERM (here I can be wrong) - amaya
kathy doyle
Transfer status, such as.
Replies:
In the sense that when a fork is generated, a copy of the process, already initialized, for example, is generated. In the case of a “simple start **** & gt; / dev / null &? ”will have to initialize each time anew (not to mention transferring data for it).

If you just need to start your own process from scratch, there are no advantages, plus fork is very slow. - eva truesdale
Is it possible to learn more about initialization, I’m interested in the difference in system resources, which method will work faster and eat less memory?
I want to understand the future, it is not clear why the question deserved a minus? This is not the subject of Habr? - sharad sundararajan
for which I have a minus, I also do not quite understand =)
you are described below ideology, I am more on the practical part:
if you want to execute some command separately from the main process and work yourself further, the “easy start” will be faster and will not eat up extra memory at the start of the command.
if you want to pick up a copy of the main process, then the fork will be more convenient because everything will be initialized in the child processes. here, the initialization is not in the understanding of the OS, but from the point of view of the process itself (an abstract example: reading configs, creating a kernel, defining what and why we are doing - this will all be done with fork in child processes). - majella
camron
very ideologically clear idea of ​​a split process
Light CMS: who used, what reviews? :: Advise the gallery on jQuery with the ability to comment on images :: Replacing & quot; captcha & quot ;? :: Tell me a normal traffic accounting system for Linux :: Where to find a translator bilingual RU EN to translate the blog engine's interface.?
Leave Repply for What are the advantages of fork on unix systems?
Useful Links