Running applications in background with getchar();

C, C++, and Visual C++
jaz
Fresh meat
Posts: 3
Joined: Sun Aug 12, 2012 11:37 pm
Contact:

Running applications in background with getchar();

Postby jaz » Sun Aug 12, 2012 11:48 pm

I have modified one of the sample applications using event handlers to write digital input changes to file. When I run the program manually it works fine, however if I try running it in the background (i.e. uploading the application through the web interface and running it as a daemon) it runs then closes straight away.

It seems that the application gets to getchar() and stops.

Is getchar() not the right approach when trying to run the application in the background?

User avatar
Patrick
Lead Developer
Posts: 3100
Joined: Mon Jun 20, 2005 8:46 am
Location: Canada
Contact:

Re: Running applications in background with getchar();

Postby Patrick » Mon Aug 13, 2012 3:23 pm

getchar doesn't work properly here because running the application as a daemon closes stdin and getchar sees this EOF and closes the program.

-Patrick

jaz
Fresh meat
Posts: 3
Joined: Sun Aug 12, 2012 11:37 pm
Contact:

Re: Running applications in background with getchar();

Postby jaz » Sun Aug 19, 2012 5:03 pm

Thanks Patrick,

Is there another way to keep the program running when in daemon mode?

User avatar
burley
Human-Cyborg Relations
Posts: 441
Joined: Tue Sep 27, 2011 2:37 pm
Location: Calgary
Contact:

Re: Running applications in background with getchar();

Postby burley » Mon Aug 20, 2012 7:50 am

If all of your code is being executed via event handlers then you should probably just have a busy loop.

eg.
while(1){sleep(1000)}

or something similar.
Brian Burley
403-282-7335 ext. 6003
support@phidgets.com

User avatar
Patrick
Lead Developer
Posts: 3100
Joined: Mon Jun 20, 2005 8:46 am
Location: Canada
Contact:

Re: Running applications in background with getchar();

Postby Patrick » Mon Aug 20, 2012 8:15 am

use usleep(100000); - sleep() doesn't always behave nicely on the sbc.

-Patrick

jaz
Fresh meat
Posts: 3
Joined: Sun Aug 12, 2012 11:37 pm
Contact:

Re: Running applications in background with getchar();

Postby jaz » Tue Aug 21, 2012 4:59 pm

All good!

Thanks guys


Return to “C/C++”

Who is online

Users browsing this forum: No registered users and 1 guest