The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
.
google unix.com



High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
script to monitor process running on server and posting a mail if any process is dead pradeepmacha Shell Programming and Scripting 13 03-06-2009 06:33 AM
daemon process suresh_rupineni Linux 1 08-21-2006 02:14 AM
zombie daemon process!! rish2005 UNIX for Advanced & Expert Users 1 11-25-2005 08:59 AM
Should a UNIX daemon process close open fds? kunalashar UNIX for Dummies Questions & Answers 1 10-24-2002 09:10 AM
what is a daemon process Kanu77 High Level Programming 6 03-08-2002 09:47 AM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Rate Thread Display Modes
  #1 (permalink)  
Old 12-26-2001
Registered User
 

Join Date: Dec 2001
Posts: 2
Angry Daemon process

Hi,
I have to write a daemon process, which performs certain operations in the background.
Now since it performs operations in the background, it should not display anything to the standard output.
The problem is that it still displays, text on standard output.
Can anyone tell me (it is urgent) how to avoid this.
I have written the following function to initialize the daemon code ...

int
daemon_init()
{
int pid, fd;

if (getppid() == 1)
{
goto out;
}

#ifdef SIGTTOU
signal(SIGTTOU, SIG_IGN);
#endif
#ifdef SIGTTIN
signal(SIGTTIN, SIG_IGN);
#endif
#ifdef SIGTSTP
signal(SIGTSTP, SIG_IGN);
#endif

pid = fork();
if (pid < 0)
{
return -1;
}
else if (pid > 0)
{
/* In parent exit leaving the child to work */
exit(0);
}

if (setpgrp() == -1)
{
return -1;
}
signal(SIGHUP, SIG_IGN);

pid = fork();
if (pid < 0)
{
return -1;
}
else if (pid > 0)
{
/* first child exits */
exit(0);
}

out:
/*for (fd = 3; fd < NOFILE; fd++)
close(fd);*/
/* In child detach from the parents session */
/*setsid();*/
chdir("/");
umask(0);

return 0;
}
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 12-26-2001
Perderabo's Avatar
Unix Daemon
 

Join Date: Aug 2001
Location: Ashburn, Virginia
Posts: 9,042
This has been discussed. If you had used this site's search function you would have found this post.
Reply With Quote
  #3 (permalink)  
Old 01-17-2002
Registered User
 

Join Date: Oct 2001
Location: Bangalore,India
Posts: 5
Post

If the daemon process is still sending text to the o/p , i think u can direct the o/p of the daemon
process to /dev/null and i think it shouldn't
be a problem
Reply With Quote
Google The UNIX and Linux Forums
Reply

Bookmarks

Tags
None

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes Rate This Thread
Rate This Thread:




All times are GMT -4. The time now is 04:05 AM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
vBCredits v1.4 Copyright ©2007 - 2008, PixelFX Studios
The UNIX and Linux Forums Content Copyright ©1993-2009. All Rights Reserved.Ad Management by RedTyger

Content Relevant URLs by vBSEO 3.2.0

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66