LinuxQuestions.org
Help answer threads with 0 replies.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 01-17-2014, 08:17 AM   #1
lemon09
Member
 
Registered: Jun 2009
Location: kolkata,India
Distribution: Mandriva,openSuse,Mint,Debian
Posts: 285
Blog Entries: 1

Rep: Reputation: 37
process creation in c++


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!!!!
 
Old 01-17-2014, 09:38 AM   #2
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,882
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930
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.
 
Old 01-17-2014, 01:55 PM   #3
lemon09
Member
 
Registered: Jun 2009
Location: kolkata,India
Distribution: Mandriva,openSuse,Mint,Debian
Posts: 285

Original Poster
Blog Entries: 1

Rep: Reputation: 37
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?
 
Old 01-17-2014, 04:38 PM   #4
dwhitney67
Senior Member
 
Registered: Jun 2006
Location: Maryland
Distribution: Kubuntu, Fedora, RHEL
Posts: 1,541

Rep: Reputation: 335Reputation: 335Reputation: 335Reputation: 335
Quote:
Originally Posted by lemon09 View Post
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.
 
Old 01-17-2014, 09:46 PM   #5
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,882
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930
Quote:
Originally Posted by lemon09 View Post
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?
 
Old 01-19-2014, 01:54 PM   #6
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: Mint, Armbian, NetBSD, Puppy, Raspbian
Posts: 3,515

Rep: Reputation: 239Reputation: 239Reputation: 239
C++ could improve fork best if it uses it to disappear up it's own backside

 
Old 01-20-2014, 07:14 AM   #7
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,882
Blog Entries: 13

Rep: Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930Reputation: 4930
Quote:
Originally Posted by bigearsbilly View Post
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?
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Get the creation time of a process via pid in C++ Cracker-Barrel Programming 4 03-23-2010 03:33 PM
How to detect new process creation? hkhalid Programming 5 09-13-2009 05:31 PM
detached process creation -? vlyamtse Programming 6 04-23-2009 02:22 PM
process creation mozala Programming 2 06-01-2006 06:31 PM
Terminal Process creation gmh04 Linux - General 0 01-25-2005 11:46 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 10:27 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration