LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
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 04-20-2013, 08:10 PM   #1
methodtwo
Member
 
Registered: May 2007
Posts: 146

Rep: Reputation: 18
Basic daemon questions


Hi there
I wrote a few TCP/IP Daemons to teach myself about one of the many aspects of Unix that i'm interested in. I wrote my own daemonize function. I sometimes use this and sometimes use the daemon function from GNU libc. In my multi-threaded version of this network daemon i can call the GNU libc daemon function and in the main thread(main function) just do:
Code:
for(;;)
   pause();
So that the threads that handle client requests in this version of the daemon, never return and are not waited for by pthread_join(). This works fine but when i use my own daemonize code then i sometimes get crazy runaway threads or processes, in the case of doing the equivalent in the multi-process version of this network daemon( if i use my own daemonize function and do not call wait() from the main process and just do a pause() as in the above example i sometimes get bad results) I was wondering why this is? Should daemonization be done before the networking setup code(socket, bind, listen) or after it?
The code for the daemonize i can post if anyone is interested in this problem. Thank you very much for any advice or comments/suggestions.
regards
 
Old 04-20-2013, 08:40 PM   #2
methodtwo
Member
 
Registered: May 2007
Posts: 146

Original Poster
Rep: Reputation: 18
I solved it by doing pthread_join() and just coding the threads as an endless loop instead of calling pause() in main. I also put the daemon call(in main) before the socket code. Sorry to ask before trying things!

Last edited by methodtwo; 04-20-2013 at 08:57 PM.
 
  


Reply



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
[SOLVED] At Daemon Questions Woodsman Slackware 9 01-10-2010 12:47 AM
GnuCash, KMyMoney - basic, basic questions - please help if you can. brjoon1021 Linux - Software 3 10-20-2008 06:27 PM
basic questions on hostname and domain name + related postfix questions Moebius Linux - Newbie 7 09-04-2007 11:50 AM
SSHD + Daemon questions ps2cho Linux - Distributions 1 06-30-2005 06:56 PM
questions about the daemon( ) function... BrianK Programming 3 10-10-2003 09:29 AM

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

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