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 |
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
Are you new to LinuxQuestions.org? Visit the following links:
Site Howto |
Site FAQ |
Sitemap |
Register Now
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
|
 |
05-30-2004, 10:16 PM
|
#1
|
LQ Newbie
Registered: May 2004
Posts: 13
Rep:
|
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?
|
|
|
05-30-2004, 10:29 PM
|
#2
|
Member
Registered: May 2004
Distribution: Gentoo, Debian, OpenBSD, NetBSD
Posts: 158
Rep:
|
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.
|
|
|
05-30-2004, 11:30 PM
|
#3
|
LQ Newbie
Registered: May 2004
Posts: 13
Original Poster
Rep:
|
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.
|
|
|
05-31-2004, 04:42 PM
|
#4
|
LQ Newbie
Registered: Jan 2004
Distribution: gentoo
Posts: 17
Rep:
|
Just run wget in the background, like so: system("wget URL_GOES_HERE&").
|
|
|
All times are GMT -5. The time now is 10:49 AM.
|
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.
|
Latest Threads
LQ News
|
|