LinuxQuestions.org
Share your knowledge at the LQ Wiki.
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-30-2004, 10:16 PM   #1
kamel
LQ Newbie
 
Registered: May 2004
Posts: 13

Rep: Reputation: 0
C++: running system() without stopping program


I'm writing a program and im wanting to call say wget with the c++ command system();

calling system("wget URL_GOES_HERE") for example will pause my program while that is executing. It isn't a problem for small files, but for bug ones its pestering. How can I make it so that the system() command will run in the background while other things in my program execute? Or is this even possible?
 
Old 05-30-2004, 10:29 PM   #2
Peterius
Member
 
Registered: May 2004
Distribution: Gentoo, Debian, OpenBSD, NetBSD
Posts: 158

Rep: Reputation: 16
Well, I'm a C programmer who looks down on object orientation. ;-) But its all basically the same. There are a number of ways to get a program to do something while the rest of the program does other things. I assume you want the system to be downloading webpages...thats what wget does right?, while your program does whatever. Easiest way to do this, is probably with the "fork()" function. Use the man pages to look it up, but basically you call fork somewhere and it creates a copy of the program in memory, it doesn't share memory with the original program, and then both processes are scheduled to run, so your program and your child process that you spawned to run wget can both run concurrently.

fork basically returns either the process id of the child process you spawned(the one running wget shortly after) or it returns 0 meaning, that its returning to the child process itself. Isn't that nifty? So its like your program literally splits in half and you can do a simple
if(!fork())
{
wget...
exit(0);
}
and its ...wow...indescribably nifty. I hope I helped you.
 
Old 05-30-2004, 11:30 PM   #3
kamel
LQ Newbie
 
Registered: May 2004
Posts: 13

Original Poster
Rep: Reputation: 0
Thank you very much: This opens up a whole new world of possibility for me. (Gonna try it as soon as i read up a bit on it and stuff)

Actually, i'm not wanting to use wget or wanting to download webpages (well, kinda i am, though not using wget). I want my program to download and parse a local copy of my Streamload account (obtained from XML files) while viewing what has been obtained so far. The program will be a much-needed linux Streamload interface program.

I dubbed it the name "Streamload Highlevel Integrated Terminal" of course, you can imagine what the acronym is. heh, intentional of course.
 
Old 05-31-2004, 04:42 PM   #4
brassfish
LQ Newbie
 
Registered: Jan 2004
Distribution: gentoo
Posts: 17

Rep: Reputation: 0
Just run wget in the background, like so: system("wget URL_GOES_HERE&").
 
  


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
Running a program rj686 Linux - Software 16 10-10-2004 07:19 PM
Listing/Stopping Running Services mooreted Slackware 15 08-20-2004 10:09 AM
need help running a program boogerman Linux - Software 8 11-24-2003 02:17 PM
stopping a command-line program from python kernelpanicguy Programming 0 09-08-2003 03:29 AM
stopping programs running when linux starts face_master Linux - General 1 02-10-2003 07:04 AM

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

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