Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 323
  • Last Modified:

How to run a program as daemon ?

I have an application which should run as daemon when user specifies -d option.
I am doing the following to make it daemon.

1)Fork
2)If successful, exit parent
3)make child as session leader
4)cd /
5)umask(0)

My application runs fine when it is not running as daemon(when -d optionnot specified)
When I specify -d option, when I debug, I can see that parent exits. then I cant track what happens.

Please help
kgreddy
0
kgreddy
Asked:
kgreddy
  • 4
  • 3
  • 2
  • +1
1 Solution
 
ahoffmannCommented:
you need a debugger which follows the forked process, or use a debugger which can attach to a running process
See man gdb for example.
0
 
Nisus091197Commented:
Under Solaris I like to use the truss command.  It is like the strace command under linux.

e.g.

truss date

Regards, Nisus
http://www.omnimodo.com
0
 
ahoffmannCommented:
 truss -p ...
is the solution then, but keep in mind that it only traces system calls
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
Nisus091197Commented:
truss -f -p pid-of-process

The -f will follow child processes.

That should do the trick.

Regards, Nisus
http://www.omnimodo.com
0
 
ecwCommented:
Yep, as nisus says, truss -f

But ...

A daemon process should not itself be a session or process group leader.  It is usual for the things to be competely disassociated from the any controlling tty (hence the session leader step), however the first tty device opened by a session or process group leader which hasn't already got a ctty, will become the controlling tty for that session or pgrp.  This is resolved by using ONOCTTY flag, or traditionally, before ONOCTTY,

  parent process forks
   first child setpgrp/setsid
   first child closes all open fd's
   first child forks
     second childs runs as daemon
   first child exits
  parent exits

0
 
MoondancerCommented:
ADMINISTRATION WILL BE CONTACTING YOU SHORTLY.  Moderators Computer101 or Netminder will return to finalize these if still open in seven days.  Please post closing recommendations before that time.

Question(s) below appears to have been abandoned. Your options are:
 
1. Accept a Comment As Answer (use the button next to the Expert's name).
2. Close the question if the information was not useful to you. You must tell the participants why you wish to do this, and allow for Expert response.
3. Ask Community Support to help split points between participating experts, or just comment here with details and we'll respond with the process.
4. Delete the question (if it has no potential value for others).
   --> Post comments for experts of your intention to delete and why
   --> You cannot delete a question with comments, special handling by a Moderator is required.

For special handling needs, please post a zero point question in the link below and include the question QID/link(s) that it regards.
http://www.experts-exchange.com/jsp/qList.jsp?ta=commspt
 
Please click the Help Desk link on the left for Member Guidelines, Member Agreement and the Question/Answer process.  http://www.experts-exchange.com/jsp/cmtyHelpDesk.jsp

Please click you Member Profile to view your question history and keep them all current with updates as the collaboration effort continues, to track all your open and locked questions at this site.  If you are an EE Pro user, use the Power Search option to find them.  Anytime you have questions which are LOCKED with a Proposed Answer but does not serve your needs, please reject it and add comments as to why.  In addition, when you do grade the question, if the grade is less than an A, please add a comment as to why.  This helps all involved, as well as future persons who may access this item in the future to seek help.

To view your open questions, please click the following link(s) and keep them all current with updates.
http://www.experts-exchange.com/questions/Q.11473240.html
http://www.experts-exchange.com/questions/Q.11667758.html
http://www.experts-exchange.com/questions/Q.20076226.html
http://www.experts-exchange.com/questions/Q.20107139.html
http://www.experts-exchange.com/questions/Q.20109162.html
http://www.experts-exchange.com/questions/Q.20109691.html
http://www.experts-exchange.com/questions/Q.20118121.html
http://www.experts-exchange.com/questions/Q.20118127.html
http://www.experts-exchange.com/questions/Q.20173258.html
http://www.experts-exchange.com/questions/Q.20240985.html
http://www.experts-exchange.com/questions/Q.20258498.html
http://www.experts-exchange.com/questions/Q.20260199.html
http://www.experts-exchange.com/questions/Q.11263994.html
http://www.experts-exchange.com/questions/Q.20270368.html
http://www.experts-exchange.com/questions/Q.20271874.html
http://www.experts-exchange.com/questions/Q.20274619.html
http://www.experts-exchange.com/questions/Q.20276268.html
http://www.experts-exchange.com/questions/Q.20276453.html
http://www.experts-exchange.com/questions/Q.20276277.html


To view your locked questions, please click the following link(s) and evaluate the proposed answer.
http://www.experts-exchange.com/questions/Q.20271075.html

PLEASE DO NOT AWARD THE POINTS TO ME.  
 
------------>  EXPERTS:  Please leave any comments regarding your closing recommendations if this item remains inactive another seven (7) days.  Also, if you are interested in the cleanup effort, please click this link http://www.experts-exchange.com/jsp/qManageQuestion.jsp?ta=commspt&qid=20274643

Moderators will finalize this question if still open in 7 days, by either moving this to the PAQ (Previously Asked Questions) at zero points, deleting it or awarding expert(s) when recommendations are made, or an independent determination can be made.  Expert input is always appreciated to determine the fair outcome.
 
Thank you everyone.
 
Moondancer
Moderator @ Experts Exchange

P.S.  For any year 2000 questions, special attention is needed to ensure the first correct response is awarded, since they are not in the comment date order, but rather in Member ID order.
0
 
Nisus091197Commented:
Hi kgreddy,

Has my suggestion been helpful?  Anything more we can help with?
0
 
MoondancerCommented:
Sorry Asker chose not to respond.  I finalized this today.
EE Moderator
0
 
Nisus091197Commented:
very festive.

Have EE stopped giving away Tshirts?  I asked for my guru one ages ago?
0
 
MoondancerCommented:
T-shirt program went away when the site was sold.  The new owners are looking at new incentive programs.  Check the "What's New" for an update now and again.  The current focus is a site-wide rewrite to fix many of the inherited roadblocks/problems.  When new incentive programs are added, they will be announced in the What's New category.
Moondancer - EE Moderator
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 4
  • 3
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now