Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

Differences between CreateProcess() in WIn32 and fork()/exec() in Unix

I need to know the difference between the two mainly when talking of address space creation of the child process. I have heard that fork() clones the address space and CreateProcess() does not. What does that mean..I request an in-depth answer.

Comments

  • digiboy86digiboy86 Posts: 8Member
    : I need to know the difference between the two mainly when talking of address space creation of the child process. I have heard that fork() clones the address space and CreateProcess() does not. What does that mean..I request an in-depth answer.
    :

    In Windows when you call CreateProcess() it does just that. It creates a new "clean" process ready to run what you say. In Linux/Unix the fork() command first creates a whole new "copy" of the current process (creating a copy of all the memory of the program that calls fork()) so now you have two duplicate processes in memory (what a waste of time and resources). Then exec() will cause the new process to exit (thereby freeing all this memory just created for the new process) and executes the new program. I don't understand the reasoning behind Linux, their multi-tasking is so messed up from what I hear. I've been developing for Linux for a while now and I gotta say Windows is better from a developers stand-point. But it's free so you can't complain!

    I'm eagerly watching the Wine (http://winehq.org) project take shape. It lets you run Win16/32 apps in Linux natively (no emulation). I've even submitted some of my own updates to the project. But reading from the "gurus" at work on the project it's hard to get Linux to do what Windows already can.


  • ilchymisilchymis Posts: 1Member
    : In Linux/Unix the fork() command first creates a whole new "copy" of
    : the current process (creating a copy of all the memory of the
    : program that calls fork()) so now you have two duplicate processes
    : in memory (what a waste of time and resources).

    You misunderstand how the fork() function works in Linux. It doesn't actually copy all that address space, it merely clones the process's page table and sets the child process's pages to copy-on-write--so no, there is no measurable "waste of time and resources". And if you're [italic]really[/italic] that concerned about performance, you can use vfork() instead, which doesn't even bother to clone the page table. In fact, if you'd done your homework at all you would know that spawning new processes on Linux is quite significantly [italic]faster[/italic] than on Windows.

    : Then exec() will cause the new process to exit (thereby freeing all
    : this memory just created for the new process) and executes the new
    : program. I don't understand the reasoning behind Linux, their multi-
    : tasking is so messed up from what I hear.

    This design (in all of POSIX-compatible operating systems, mind you, not just Linux) is because in many instances it is quite useful to do a fork without an exec--which Windows cannot do. Refer to how the Apache web server takes advantage of this feature in its multi-processing models, for instance.

    I guess you heard wrong.

    : I've been developing for Linux for a while now and I gotta say Windows
    : is better from a developers stand-point.

    Regrettably, it seems you have not been developing for Linux nearly long enough to obtain even a basic understanding of the operating system's design principles, let alone the true advantages and disadvantages of those principles.

    : But reading from the "gurus" at work on the project it's hard to get
    : Linux to do what Windows already can.

    You might want to get a second opinion there.
Sign In or Register to comment.