Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place! |
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.
|
|
10-02-2007, 02:10 PM
|
#1
|
Member
Registered: Aug 2006
Posts: 40
Rep:
|
Running C Program in Background help
I have recently registered for a free shell account so that i can use it to test C Programs from any Windows PC using the net. Now the problem is that i have made a server program which needs to run in the background, but when i try doing that using & its not working,the program starts running and even pressing Ctrl+Z it wont go to the background! Any idea whats wrong?
|
|
|
10-02-2007, 03:15 PM
|
#2
|
Member
Registered: Nov 2004
Location: Novi Sad, Serbia
Distribution: Debian, Slackware, Gentoo, openSuSE
Posts: 254
Rep:
|
Start it this way:
nohup program &
Or use screen.
|
|
|
10-02-2007, 03:38 PM
|
#3
|
Member
Registered: Aug 2006
Posts: 40
Original Poster
Rep:
|
i am using it like this:
./programObject&
And whats screen??
|
|
|
10-02-2007, 08:45 PM
|
#4
|
LQ Guru
Registered: Aug 2004
Location: Sydney
Distribution: Rocky 9.2
Posts: 18,419
|
You need a space between the prog name and the '&'.
Using nohup as well ensures it'll keep running if you logout, otherwise it's still 'attached' to your terminal, even though it's in background mode.
IOW, do as per kotnik's example
|
|
|
10-03-2007, 08:06 AM
|
#5
|
Senior Member
Registered: Dec 2005
Location: London, ON, Canada
Distribution: Arch, Ubuntu, Slackware, OpenBSD, FreeBSD
Posts: 1,853
Rep:
|
Have you tried forking the program? I'm not sure if that's the proper terminology, as I'm not a C or C++ programmer. The method I'm referring to goes like this:
1. Start Program1.
2. Spawn a child process for the main algorithm.
3. The parent process dies, as it is finished, and the child process does what it's supposed to do.
|
|
|
10-03-2007, 12:26 PM
|
#6
|
Member
Registered: Aug 2006
Posts: 40
Original Poster
Rep:
|
ok this is whats happeneing:
When i run the program with this command: ./ProgramObject<SPACE>& the program starts running on screen and does not go to the background even by pressing Ctrl+Z. And using nohup also does not make any difference.
But the program is running fine in my college PC which runs Linux. So is the problem with my Shell Account?
|
|
|
10-03-2007, 12:41 PM
|
#7
|
Senior Member
Registered: Dec 2005
Location: London, ON, Canada
Distribution: Arch, Ubuntu, Slackware, OpenBSD, FreeBSD
Posts: 1,853
Rep:
|
If a program produces output while it runs, it will most definitely print the output to the shell is was run from.
To get rid of the output, you need to pipe it to a different source.
Code:
$ ./ProgramObject & >> ProgramObject.log #For debugging
$ ./ProgramObject & > /dev/null #If you don't need the output
While I highly doubt that it may be an issue with your shell account, it shouldn't be dismissed as a culprit.
Last edited by indienick; 10-03-2007 at 12:42 PM.
Reason: Pointing fingers
|
|
|
10-04-2007, 03:41 PM
|
#8
|
Member
Registered: Aug 2006
Posts: 40
Original Poster
Rep:
|
Quote:
Originally Posted by indienick
If a program produces output while it runs, it will most definitely print the output to the shell is was run from.
To get rid of the output, you need to pipe it to a different source.
Code:
$ ./ProgramObject & >> ProgramObject.log #For debugging
$ ./ProgramObject & > /dev/null #If you don't need the output
While I highly doubt that it may be an issue with your shell account, it shouldn't be dismissed as a culprit.
|
Tried it, but still same problem!
|
|
|
All times are GMT -5. The time now is 03:31 PM.
|
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
|
|