Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
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.


  Search this Thread
Old 05-22-2005, 11:57 AM   #1
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);

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

Thanks, Damian.
Old 05-22-2005, 01:40 PM   #2
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
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
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
Registered: May 2005
Posts: 378

Rep: Reputation: 33
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
Senior Member
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 110Reputation: 110
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.


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 > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 06:38 PM.

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