LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
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 06-27-2004, 10:56 PM   #1
kamransoomro84
Member
 
Registered: Feb 2004
Location: Pakistan
Distribution: OpenSUSE 10.2
Posts: 241

Rep: Reputation: 30
Executing another application


Hi.

I'm calling pico from my program using execl. Everything works fine except that I can't get my program to wait until pico returns to procedd further. Is there any way to do that?

Thanks.
 
Old 06-28-2004, 01:29 AM   #2
itsme86
Senior Member
 
Registered: Jan 2004
Location: Oregon, USA
Distribution: Slackware
Posts: 1,246

Rep: Reputation: 59
Use the wait() function.
Code:
if(!fork())
{
  // Call pico with execl()
  exit(0);
}

wait(NULL);  // Pause your program until child process exits
 
Old 06-28-2004, 08:55 AM   #3
kamransoomro84
Member
 
Registered: Feb 2004
Location: Pakistan
Distribution: OpenSUSE 10.2
Posts: 241

Original Poster
Rep: Reputation: 30
You mean fork() should return zero for me to proceed further? I've been trying to figure out how that works. Let me guess, fork reserves a process slot for your application so that the next process you call takes over that slot and becomes the child process, right? And the pid returned by fork will be taken up by pico. Am I on the mark? Please tell me. Thanks.
 
Old 06-28-2004, 09:03 AM   #4
itsme86
Senior Member
 
Registered: Jan 2004
Location: Oregon, USA
Distribution: Slackware
Posts: 1,246

Rep: Reputation: 59
fork() returns twice. Once inside the parent process and once inside the child. In the parent it returns the PID of the child process and in the child process it returns 0. So by doing if(!fork()) any code that follows in the code block is executed by the child and the parent will continue after the if() code block.

When you call fork() it creates a copy of the running process, but as soon as you call one of the exec() family of functions it replaces the current process (the child in this case) with whatever program you tell it to. So you were on the right track. Very close It's just not really a reservation. If you fork() and don't call an exec() function you'll have 2 copies of the original process running, but the child would start right after the fork() call, not at main().

Hope that explains it! Let me know if it still doesn't make sense.

Last edited by itsme86; 06-28-2004 at 09:05 AM.
 
Old 06-29-2004, 11:36 AM   #5
kamransoomro84
Member
 
Registered: Feb 2004
Location: Pakistan
Distribution: OpenSUSE 10.2
Posts: 241

Original Poster
Rep: Reputation: 30
Ah, yes, I get. Thankyou very much. It makes a lot of sense.
 
  


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
how to link helpblocks application to gtk application m.harshavardhan Linux - Software 0 08-16-2005 08:39 AM
Executing from cgi theonebeyond Programming 4 10-04-2004 11:30 PM
executing on startup moschi Linux - General 7 09-06-2004 12:49 PM
how i migrate windows application to Linux base application vandarakalpesh Linux - Software 0 06-26-2004 03:34 AM
executing programs?!? cmargiol Linux - General 8 10-29-2003 02:38 PM

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

All times are GMT -5. The time now is 04:00 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