ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
Well, in C we have functions like fork() and exec() to create a separate process from within a program. The header files that they use is
Code:
#include <unistd.h>
Now, the question is - what is the C++ equivalent of this code. Do we have separate functions for these or they are just the same in C++. Also that C++ uses its own style headers, like:
Code:
#include <iostream>
followed by the namespace to use. For process creation in C++ do we have such header files and namespaces??
Any tutorial with proper examples would be appreciated. Thanks!!!!
You can do that exact same things in C++ that you can do with C in invoking fork() and exec(). I do this all the time. I also however do include <unistd.h> in that form in a C++ program.
Yes, I know that I can do it in the same way we do in C. But my question was - is there any specific way of doing this in C++ which is a bit different from C?
Yes, I know that I can do it in the same way we do in C. But my question was - is there any specific way of doing this in C++ which is a bit different from C?
No. (which makes you wonder why anyone would every bother developing in C, unless they are relegated to using a puny compiler for a specific microprocessor).
Last edited by dwhitney67; 01-17-2014 at 04:40 PM.
Yes, I know that I can do it in the same way we do in C. But my question was - is there any specific way of doing this in C++ which is a bit different from C?
Possibly, but none that I in know of. I'm thinking that pretty much most Linux library functions are written in C, as is the kernel; hence to me it's best to stick with the C implementation. And further, wouldn't a C++ implementation risk being not better but instead worse because it would be a rewrite of an already existing proven function? What particular aspect of C++ would you think could improve fork() as it stands today? Granted one could create a higher order fork() function with overloads, but what would you suggest?
C++ could improve fork best if it uses it to disappear up it's own backside
Joking? Or did you mean something like automatically monitoring for signals from the child so that it would avoid zombies, or give distinct API's so that people would use signals they might otherwise ignore?
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.