LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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 05-22-2005, 11:57 AM   #1
grupoapunte
LQ Newbie
 
Registered: Apr 2005
Posts: 26

Rep: Reputation: 15
Question I want to start a prog from another prog but not as child


Hi, I need to know if theres a way to start a program from another program without using fork() the thing is i dont want that the new program apears like child of the first one, both programs execute in a console, and the program i want to start has no usr interface (it runs in background), I have already tryed this in my code but didnt work:

sprintf(eHab->cBuffIO, "./Persona %s %hd no", eHab->cIp, eHab->usPuerto);
system(eHab->cBuffIO);

./Persona is the program, and eHab->cIp, eHab->usPuerto are the params

Thanks, Damian.
 
Old 05-22-2005, 01:40 PM   #2
eddiebaby1023
Member
 
Registered: May 2005
Posts: 378

Rep: Reputation: 33
Use one of the exec(3) family of system calls. man 3 exec for details. Ask here again if you need clarification of what you've read.
 
Old 05-22-2005, 02:07 PM   #3
grupoapunte
LQ Newbie
 
Registered: Apr 2005
Posts: 26

Original Poster
Rep: Reputation: 15
In first place thanks for your help, I know about those functions, cant use them, sry I forgot to say that I need both programs working, the problem is that those functions remplace the program that calls it by the new prog thats being executed, the way to avoid that is using fork() but the new program will apear as a child, and I cant do that.

If you know about any other way to do it, or if thers no posible way, please tell me.

Thanks again Damian.
 
Old 05-22-2005, 08:14 PM   #4
randyding
Member
 
Registered: May 2004
Posts: 552

Rep: Reputation: 31
You must then fork() twice. The first fork starts a second fork and then the first one terminates, causing the process to be owned by init process.
 
Old 05-23-2005, 05:12 PM   #5
eddiebaby1023
Member
 
Registered: May 2005
Posts: 378

Rep: Reputation: 33
Quote:
the new program will apear as a child, and I cant do that.
All processes have a parent process so they all appear to run as a child. Or do you mean it mustn't be owned by the spawning process (in which case randyding's reply is your answer)? Any particular reason - I'm intrigued?
 
Old 05-23-2005, 05:37 PM   #6
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: ubuntu
Posts: 2,530

Rep: Reputation: 108Reputation: 108
You could fork() the program, then call daemon(0,0).
After daemon(0,0) the program will not have any terminal to talk to anymore though.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

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
Updated libpng, now existing GTK prog won't start anymore - Rh9 rylan76 Linux - Software 1 05-12-2005 01:06 PM
[C prog] how to do this? dmigh Programming 7 10-31-2004 03:45 AM
Better buying "advanced linux prog" or "unix advanced prog" Dominik Programming 3 12-31-2003 01:11 PM
start prog lineakd with X twk Linux - General 1 09-10-2002 02:29 AM
How to start a prog in another terminal ? gluon Linux - General 3 07-18-2002 12:03 PM


All times are GMT -5. The time now is 04:29 PM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration