?
Solved

How to run a program as daemon ?

Posted on 2002-03-07
10
Medium Priority
?
315 Views
Last Modified: 2013-12-27
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
Comment
Question by:kgreddy
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
  • +1
10 Comments
 
LVL 51

Expert Comment

by:ahoffmann
ID: 6848499
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
 
LVL 5

Expert Comment

by:Nisus091197
ID: 6851037
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
 
LVL 51

Expert Comment

by:ahoffmann
ID: 6851290
 truss -p ...
is the solution then, but keep in mind that it only traces system calls
0
Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

 
LVL 5

Accepted Solution

by:
Nisus091197 earned 200 total points
ID: 6852036
truss -f -p pid-of-process

The -f will follow child processes.

That should do the trick.

Regards, Nisus
http://www.omnimodo.com
0
 
LVL 5

Expert Comment

by:ecw
ID: 6855068
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
 
LVL 1

Expert Comment

by:Moondancer
ID: 6892775
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
 
LVL 5

Expert Comment

by:Nisus091197
ID: 6915667
Hi kgreddy,

Has my suggestion been helpful?  Anything more we can help with?
0
 
LVL 1

Expert Comment

by:Moondancer
ID: 6940829
Sorry Asker chose not to respond.  I finalized this today.
EE Moderator
0
 
LVL 5

Expert Comment

by:Nisus091197
ID: 6940946
very festive.

Have EE stopped giving away Tshirts?  I asked for my guru one ages ago?
0
 
LVL 1

Expert Comment

by:Moondancer
ID: 6958456
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

Get real performance insights from real users

Key features:
- Total Pages Views and Load times
- Top Pages Viewed and Load Times
- Real Time Site Page Build Performance
- Users’ Browser and Platform Performance
- Geographic User Breakdown
- And more

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In tuning file systems on the Solaris Operating System, changing some parameters of a file system usually destroys the data on it. For instance, changing the cache segment block size in the volume of a T3 requires that you delete the existing volu…
My previous tech tip, Installing the Solaris OS From the Flash Archive On a Tape (http://www.experts-exchange.com/articles/OS/Unix/Solaris/Installing-the-Solaris-OS-From-the-Flash-Archive-on-a-Tape.html), discussed installing the Solaris Operating S…
Learn several ways to interact with files and get file information from the bash shell. ls lists the contents of a directory: Using the -a flag displays hidden files: Using the -l flag formats the output in a long list: The file command gives us mor…
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Suggested Courses

777 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question