Daemon programming: allocated memory vs. fork()

This is a discussion on Daemon programming: allocated memory vs. fork() within the Linux Programming forums, part of the Platform Specific Boards category; Hi, I experienced some problems while porting some programs from Solaris to Linux. They are all calling fork() after being ...

  1. #1
    Registered User
    Join Date
    Sep 2003
    Posts
    3

    Question Daemon programming: allocated memory vs. fork()

    Hi,
    I experienced some problems while porting some programs from Solaris to Linux. They are all calling fork() after being started so they run in daemon mode. I also have a debug mode that just skip the daemonize function that I wrote. (this function actually just call the fork method and make the parent process to exit normally and the child process to continu the execution of the program).

    My problem is that while it run in daemon mode, it exit after a while without any warning/error/log message/etc... so I really don't know what is happening. I tested for days in debug mode and it works just fine and could run for months without problem.

    So, I guess that it's all coming from the dameonize function that is actually calling fork(). I have few question that may answer and solve my problem:

    1- Normally on Solaris, fork() duplicate the overall memory space of a process, is it the same under Linux or should I make alll my dynamic memory allocation after the fork() call?

    2-What is the difference with the other fork() function: vfork, and so on... ? Is one of them more appropriate for what I'm doing?

    3-Any other thought/suggestions about this?

    Thank you very much!

    P.S.: this was actually a reply made into another thread, but like it is a completely different fork() issue than the previous thread, I just decided to create a new thread for it...

  2. #2
    Registered User
    Join Date
    Jan 2002
    Location
    Vancouver
    Posts
    2,220
    you could always run it in the background without forking by typing

    ./server &

  3. #3
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    Originally posted by Brian
    you could always run it in the background without forking by typing

    ./server &
    And use nohup
    When all else fails, read the instructions.
    If you're posting code, use code tags: [code] /* insert code here */ [/code]

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 7
    Last Post: 02-06-2009, 11:27 AM
  2. Check if there is memory allocated
    By The Wazaa in forum C++ Programming
    Replies: 3
    Last Post: 04-23-2006, 05:48 AM
  3. Pointer's
    By xlordt in forum C Programming
    Replies: 13
    Last Post: 10-14-2003, 02:15 PM
  4. Memory handler
    By Dr. Bebop in forum C Programming
    Replies: 7
    Last Post: 09-15-2002, 04:14 PM
  5. deleting dynamically allocated memory...
    By heljy in forum C++ Programming
    Replies: 2
    Last Post: 09-08-2002, 11:40 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21