The UNIX and Linux Forums  
Hello and Welcome from United States to the UNIX and Linux Forums! Thank You for Visiting and Joining Our Global Community.

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
.
google unix.com



High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
launch a command only if Minguccio75 UNIX for Advanced & Expert Users 10 02-16-2007 07:48 AM
launch an executable from a C++ program nadiamihu High Level Programming 2 11-03-2006 05:59 AM
how to Launch an independent process. deepthi UNIX for Dummies Questions & Answers 1 03-10-2005 10:12 AM
How do you launch an .exe from my app? kapolani High Level Programming 1 01-03-2005 06:00 PM
launch & monitor process on remote host mrx Shell Programming and Scripting 1 10-15-2004 10:20 AM

Closed Thread
English Japanese Spanish French German Portuguese Italian Dutch Swedish Russian Norwegian Hungarian Hebrew Danish Bulgarian Greek Powered by Powered by Google
 
LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 05-05-2008
hr94131 hr94131 is offline
Registered User
  
 

Join Date: May 2008
Posts: 2
How to launch a new process

Hi, I have a situation where a C main program needs to call another C main program, my background is mostly Windows and I'm new to UNIX programming. I've read about system(), fork(), and exec() and I'm a little confused as to what the sequence of steps should be to launch another process. By the way the parent program would have to suspend execution until the child program returns and parent program would need to read the return or exit code of the child program. Thank you in advance for your help.

Last edited by hr94131; 05-05-2008 at 12:48 PM..
  #2 (permalink)  
Old 05-05-2008
fabtagon fabtagon is offline
Registered User
  
 

Join Date: Apr 2008
Location: European Union/Germany
Posts: 189
Should your program 1 run, while programm 2 is running? -> fork(), exec()

Else use system(), you can call any program through it.
  #3 (permalink)  
Old 05-05-2008
shamrock shamrock is offline Forum Advisor  
Registered User
  
 

Join Date: Oct 2007
Location: USA
Posts: 750
The sequence is pipe() / fork() / exec() / waitpid(). Last call reads the exit status of the child process. Use of system() is discouraged as it's costly and resource intensive.
  #4 (permalink)  
Old 05-05-2008
fabtagon fabtagon is offline
Registered User
  
 

Join Date: Apr 2008
Location: European Union/Germany
Posts: 189
system() costs mainly the memory for a shell instance. It's secure when the programmer considers the environement (variables) to be unreliable/hostile.

One has to consider what's more important: simplicity of code (system()) or efficiency (fork(), exec(), ...)
  #5 (permalink)  
Old 05-05-2008
ramen_noodle ramen_noodle is offline Forum Advisor  
Registered User
  
 

Join Date: Dec 2007
Location: Virginia, USA.
Posts: 251
Last time I checked system() was deprecated in that it uses /bin/sh -c and is a security risk due to set(u|g)id privilege escalation and environment manipulation attacks.

There's a good case that spawning a shell to execute a command is not a good idea (as shamrock noted) if a simple exec will suffice.
  #6 (permalink)  
Old 05-05-2008
hr94131 hr94131 is offline
Registered User
  
 

Join Date: May 2008
Posts: 2
Hi, thank you all for your quick reply.
Hec
Closed Thread

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:

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 On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On




All times are GMT -4. The time now is 11:13 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited. Language Translations Powered by .
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0