LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
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 09-24-2012, 09:19 AM   #1
Pluvius
LQ Newbie
 
Registered: Aug 2011
Posts: 13

Rep: Reputation: Disabled
Trouble running application as a daemon


Hello guys!

I've written an application (C++/Qt) and now my boss wants to run it as a daemon; when it's killed it respawns, there can only be one instance of the application running, starts at boot etc...

What I've accomplished so far:

-The daemon starts but then its process id is not found when I try to stop it:

I've started with a fairly simple application: hello world, I've noticed that when I start the daemon (/etc/init.d/example start) it starts, prints hello world and then exits, and the daemon is nowhere to be found among the process ids, so I've added an infinite loop and this time around the daemon's id was still there.

But I'm thinking that there's a better way for this, I've read about child processes and fork(), I don't know if it can be done this way:

-father process (the actual daemon) starts a child process which carries the application's code.

I'm a bit stuck here so any help would be welcome

Thank you very much
 
Old 09-24-2012, 11:22 AM   #2
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,399
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
You can almost never make a Qt application that launches as a boot-time daemon. A daemon process is one which has no controlling tty. A Qt application will require an X server, in order to run. Unless the X server is hosted somewhere on another host, there will be no X server when your daemon is launched. Whether a process is respawned or not does not determine whether it is or isn't a daemon, although the notion of respawning is a related concept.

You haven't said anything about what your daemon process is supposed to do. I wonder whether your purpose couldn't be adequately served by something that simply runs periodically, such as a cron job. Your wording of the question seems a bit vague on that.

--- rod.
 
1 members found this post helpful.
Old 09-25-2012, 05:30 AM   #3
Pluvius
LQ Newbie
 
Registered: Aug 2011
Posts: 13

Original Poster
Rep: Reputation: Disabled
Hello again and thanks for taking the time to help me!

I apologize for being vague, I'll try to explain a little bit more:

my Qt application doesn't rely on X but rather operates directly through the framebuffer.

My application will run in a kiosk manner; graphical interface that allows user input, if it crashes, it respawns back. cron is good but we want to exploit the openrc functionalities (I'm on Gentoo Linux), thus, a daemon would fit our needs.

I've found a possible way, but I'd be grateful if you could tell me if I'm correct:

http://www.netzmafia.de/skripten/uni...mon-howto.html

It's under the (writing the daemon code) section.
 
Old 09-25-2012, 06:12 AM   #4
lyle_s
Member
 
Registered: Jul 2003
Distribution: Slackware
Posts: 392

Rep: Reputation: 55
A few things that might help you out:

http://0pointer.de/lennart/projects/libdaemon/

http://software.clapper.org/daemonize/

Lyle.
 
1 members found this post helpful.
Old 10-08-2012, 07:04 AM   #5
Pluvius
LQ Newbie
 
Registered: Aug 2011
Posts: 13

Original Poster
Rep: Reputation: Disabled
Hello people! sorry for my late response, I was able to run the application as a daemon on gentoo using libdaemon

thank you for your help
 
  


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 communicate between a daemon and an application [IPC] ebinjose Programming 1 07-03-2012 05:30 AM
SCIM daemon launches when running any application as root. camphor Slackware 2 02-07-2009 12:53 PM
Trouble with running a GTK+ application Harry_Chang Linux - Software 2 01-24-2007 04:15 AM
Trouble running application in Fedora Core jaldana Fedora 1 12-12-2005 10:27 AM
How To Program Daemon(Service) Application wlmapp3 Programming 6 07-23-2003 03:58 PM

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

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