fork freeze - Unix

This is a discussion on fork freeze - Unix ; Hi, I have a fork freeze problem in my application, and i would appreciate some help. I've got a process that forks a reader process and some performer process, they're communicate through sockets (read, write functions). The main process works ...

+ Reply to Thread
Results 1 to 15 of 15

Thread: fork freeze

  1. fork freeze

    Hi,
    I have a fork freeze problem in my application, and i would appreciate
    some help.

    I've got a process that forks a reader process and some performer
    process, they're communicate through sockets (read, write functions).
    The main process works like a "man-in-the-middle" (child processes
    sending him data, and he passes them next).
    I've have a signal handler, for the child processes, if they crashed,
    the main processes forks them again ... until all the data has been
    processed (with remembering the bad data, and excluding it)

    Everything works fine, (socket communication, child process works like
    they should). But when a performer process has crashed, and I try to
    fork it again, then the parent process get freezed on this fork
    command, like there was a deadlock ( => stops managing communcation
    from other running child processes)

    The crashed child process returns signal 8 (floating-point exception)

    I cannot figure out, what can be the blocking element, maybe something
    with the sockets?

    got someone the same problem ?


  2. Re: fork freeze

    m4r3ck wrote:
    > Hi,
    > I have a fork freeze problem in my application, and i would appreciate
    > some help.
    >
    > I've got a process that forks a reader process and some performer
    > process, they're communicate through sockets (read, write functions).
    > The main process works like a "man-in-the-middle" (child processes
    > sending him data, and he passes them next).
    > I've have a signal handler, for the child processes, if they crashed,
    > the main processes forks them again ... until all the data has been
    > processed (with remembering the bad data, and excluding it)
    >
    > Everything works fine, (socket communication, child process works like
    > they should). But when a performer process has crashed, and I try to
    > fork it again, then the parent process get freezed on this fork
    > command, like there was a deadlock ( => stops managing communcation
    > from other running child processes)
    >
    > The crashed child process returns signal 8 (floating-point exception)
    >
    > I cannot figure out, what can be the blocking element, maybe something
    > with the sockets?
    >
    > got someone the same problem ?
    >



    Did you try to strace ? It would help you to know which system call
    your process is freezing on.

  3. Re: fork freeze

    On Apr 11, 4:00 pm, Gianni Mariani wrote:
    > m4r3ck wrote:
    > > Hi,
    > > I have a fork freeze problem in my application, and i would appreciate
    > > some help.

    >
    > > I've got a process that forks a reader process and some performer
    > > process, they're communicate through sockets (read, write functions).
    > > The main process works like a "man-in-the-middle" (child processes
    > > sending him data, and he passes them next).
    > > I've have a signal handler, for the child processes, if they crashed,
    > > the main processes forks them again ... until all the data has been
    > > processed (with remembering the bad data, and excluding it)

    >
    > > Everything works fine, (socket communication, child process works like
    > > they should). But when a performer process has crashed, and I try to
    > > fork it again, then the parent process get freezed on this fork
    > > command, like there was a deadlock ( => stops managing communcation
    > > from other running child processes)

    >
    > > The crashed child process returns signal 8 (floating-point exception)

    >
    > > I cannot figure out, what can be the blocking element, maybe something
    > > with the sockets?

    >
    > > got someone the same problem ?

    >
    > Did you try to strace ? It would help you to know which system call
    > your process is freezing on.


    yes, it was the kernel call: fork()


  4. Re: fork freeze

    On Apr 11, 1:45 pm, "m4r3ck" wrote:
    > Hi,
    > I have a fork freeze problem in my application, and i would appreciate
    > some help.
    >
    > I've got a process that forks a reader process and some performer
    > process, they're communicate through sockets (read, write functions).
    > The main process works like a "man-in-the-middle" (child processes
    > sending him data, and he passes them next).
    > I've have a signal handler, for the child processes, if they crashed,
    > the main processes forks them again ... until all the data has been
    > processed (with remembering the bad data, and excluding it)
    >
    > Everything works fine, (socket communication, child process works like
    > they should). But when a performer process has crashed, and I try to
    > fork it again, then the parent process get freezed on this fork
    > command, like there was a deadlock ( => stops managing communcation
    > from other running child processes)
    >
    > The crashed child process returns signal 8 (floating-point exception)
    >
    > I cannot figure out, what can be the blocking element, maybe something
    > with the sockets?


    Are you calling fork() from a signal handler? If so, it might be
    pthread_atfork() handlers calling async not safe functions or
    something like that.

    http://www.opengroup.org/onlinepubs/...ions/fork.html

    A process shall be created with a single thread. If a multi-threaded
    process calls fork(), the new process shall contain a replica of the
    calling thread and its entire address space, possibly including the
    states of mutexes and other resources. Consequently, to avoid errors,
    the child process may only execute async-signal-safe operations until
    such time as one of the exec functions is called.
    [THR] [Option Start] Fork handlers may be established by means of the
    pthread_atfork() function in order to maintain application invariants
    across fork() calls. [Option End]
    When the application calls fork() from a signal handler and any of the
    fork handlers registered by pthread_atfork() calls a function that is
    not asynch-signal-safe, the behavior is undefined.



  5. Re: fork freeze

    m4r3ck wrote:

    > > > I cannot figure out, what can be the blocking element, maybe something
    > > > with the sockets?

    > >
    > > > got someone the same problem ?


    This is assuredly a bug in your code, or the next feasible--but very
    slight--possibility would be an issue w/ how your execution environment is
    setup (wierd kernel modules, etc).

    > > Did you try to strace ? It would help you to know which system call
    > > your process is freezing on.

    >
    > yes, it was the kernel call: fork()


    More often than not when a process locks up on *me* its actually simply
    stuck in a loop. strace will not give coverage to the vast majority of your
    code, and leaving aside mitigating factors, statistically the bugs are more
    likely to appear in your own code. The fact that fork() was the
    _last_ syscall doesn't say much itself (is it really pending, as-in strace
    doesn't show the return value?).

    In this particular case you should try to attach to the frozen process with
    GDB (if possible), or another debugger of your choice. For gdb:

    gdb -p

    Then just get a backtrace using the `bt' command. That will give you a
    better place to begin looking. I would be surprised if it shows that you're
    _still_ at the fork() call.

    After you resolve that issue, or maybe while resolving it, you should
    definitely employ valgrind (or purify). I bet it will find at least a few
    interesting bugs.


  6. Re: fork freeze

    On Apr 12, 9:55 am, "Maxim Yegorushkin"
    wrote:
    > On Apr 11, 1:45 pm, "m4r3ck" wrote:
    >
    >
    >
    > > Hi,
    > > I have a fork freeze problem in my application, and i would appreciate
    > > some help.

    >
    > > I've got a process that forks a reader process and some performer
    > > process, they're communicate through sockets (read, write functions).
    > > The main process works like a "man-in-the-middle" (child processes
    > > sending him data, and he passes them next).
    > > I've have a signal handler, for the child processes, if they crashed,
    > > the main processes forks them again ... until all the data has been
    > > processed (with remembering the bad data, and excluding it)

    >
    > > Everything works fine, (socket communication, child process works like
    > > they should). But when a performer process has crashed, and I try to
    > > fork it again, then the parent process get freezed on this fork
    > > command, like there was a deadlock ( => stops managing communcation
    > > from other running child processes)

    >
    > > The crashed child process returns signal 8 (floating-point exception)

    >
    > > I cannot figure out, what can be the blocking element, maybe something
    > > with the sockets?

    >
    > Are you calling fork() from a signal handler? If so, it might be
    > pthread_atfork() handlers calling async not safe functions or
    > something like that.
    >
    > http://www.opengroup.org/onlinepubs/...ions/fork.html
    >
    > A process shall be created with a single thread. If a multi-threaded
    > process calls fork(), the new process shall contain a replica of the
    > calling thread and its entire address space, possibly including the
    > states of mutexes and other resources. Consequently, to avoid errors,
    > the child process may only execute async-signal-safe operations until
    > such time as one of the exec functions is called.
    > [THR] [Option Start] Fork handlers may be established by means of the
    > pthread_atfork() function in order to maintain application invariants
    > across fork() calls. [Option End]
    > When the application calls fork() from a signal handler and any of the
    > fork handlers registered by pthread_atfork() calls a function that is
    > not asynch-signal-safe, the behavior is undefined.
    >


    Oh, maybe a use wrong terms.
    By a signal handler I mean that the parent process has :
    signal(SIGCHLD, signal_handler_func()) call.
    I don't use threads explicitly at all.

    progress info:
    i've tried to replace the fork call by vfork, it didn't freezed, but I
    have problem to share some data between parent and child processes
    (through message queue)

    thanks for response


  7. Re: fork freeze

    On Apr 12, 9:54 am, "m4r3ck" wrote:
    > On Apr 12, 9:55 am, "Maxim Yegorushkin"
    > wrote:
    >
    >
    >
    > > On Apr 11, 1:45 pm, "m4r3ck" wrote:

    >
    > > > Hi,
    > > > I have a fork freeze problem in my application, and i would appreciate
    > > > some help.

    >
    > > > I've got a process that forks a reader process and some performer
    > > > process, they're communicate through sockets (read, write functions).
    > > > The main process works like a "man-in-the-middle" (child processes
    > > > sending him data, and he passes them next).
    > > > I've have a signal handler, for the child processes, if they crashed,
    > > > the main processes forks them again ... until all the data has been
    > > > processed (with remembering the bad data, and excluding it)

    >
    > > > Everything works fine, (socket communication, child process works like
    > > > they should). But when a performer process has crashed, and I try to
    > > > fork it again, then the parent process get freezed on this fork
    > > > command, like there was a deadlock ( => stops managing communcation
    > > > from other running child processes)

    >
    > > > The crashed child process returns signal 8 (floating-point exception)

    >
    > > > I cannot figure out, what can be the blocking element, maybe something
    > > > with the sockets?

    >
    > > Are you calling fork() from a signal handler? If so, it might be
    > > pthread_atfork() handlers calling async not safe functions or
    > > something like that.

    >
    > >http://www.opengroup.org/onlinepubs/...ions/fork.html
    > >
    > > A process shall be created with a single thread. If a multi-threaded
    > > process calls fork(), the new process shall contain a replica of the
    > > calling thread and its entire address space, possibly including the
    > > states of mutexes and other resources. Consequently, to avoid errors,
    > > the child process may only execute async-signal-safe operations until
    > > such time as one of the exec functions is called.
    > > [THR] [Option Start] Fork handlers may be established by means of the
    > > pthread_atfork() function in order to maintain application invariants
    > > across fork() calls. [Option End]
    > > When the application calls fork() from a signal handler and any of the
    > > fork handlers registered by pthread_atfork() calls a function that is
    > > not asynch-signal-safe, the behavior is undefined.
    > >

    >
    > Oh, maybe a use wrong terms.
    > By a signal handler I mean that the parent process has :
    > signal(SIGCHLD, signal_handler_func()) call.
    > I don't use threads explicitly at all.


    Do you call fork() from the signal handler, that is, from
    signal_handler_func?


  8. Re: fork freeze

    On Apr 12, 11:25 am, "Maxim Yegorushkin"
    wrote:
    > On Apr 12, 9:54 am, "m4r3ck" wrote:
    >
    >
    >
    > > On Apr 12, 9:55 am, "Maxim Yegorushkin"
    > > wrote:

    >
    > > > On Apr 11, 1:45 pm, "m4r3ck" wrote:

    >
    > > > > Hi,
    > > > > I have a fork freeze problem in my application, and i would appreciate
    > > > > some help.

    >
    > > > > I've got a process that forks a reader process and some performer
    > > > > process, they're communicate through sockets (read, write functions).
    > > > > The main process works like a "man-in-the-middle" (child processes
    > > > > sending him data, and he passes them next).
    > > > > I've have a signal handler, for the child processes, if they crashed,
    > > > > the main processes forks them again ... until all the data has been
    > > > > processed (with remembering the bad data, and excluding it)

    >
    > > > > Everything works fine, (socket communication, child process works like
    > > > > they should). But when a performer process has crashed, and I try to
    > > > > fork it again, then the parent process get freezed on this fork
    > > > > command, like there was a deadlock ( => stops managing communcation
    > > > > from other running child processes)

    >
    > > > > The crashed child process returns signal 8 (floating-point exception)

    >
    > > > > I cannot figure out, what can be the blocking element, maybe something
    > > > > with the sockets?

    >
    > > > Are you calling fork() from a signal handler? If so, it might be
    > > > pthread_atfork() handlers calling async not safe functions or
    > > > something like that.

    >
    > > >http://www.opengroup.org/onlinepubs/...ions/fork.html
    > > >
    > > > A process shall be created with a single thread. If a multi-threaded
    > > > process calls fork(), the new process shall contain a replica of the
    > > > calling thread and its entire address space, possibly including the
    > > > states of mutexes and other resources. Consequently, to avoid errors,
    > > > the child process may only execute async-signal-safe operations until
    > > > such time as one of the exec functions is called.
    > > > [THR] [Option Start] Fork handlers may be established by means of the
    > > > pthread_atfork() function in order to maintain application invariants
    > > > across fork() calls. [Option End]
    > > > When the application calls fork() from a signal handler and any of the
    > > > fork handlers registered by pthread_atfork() calls a function that is
    > > > not asynch-signal-safe, the behavior is undefined.
    > > >

    >
    > > Oh, maybe a use wrong terms.
    > > By a signal handler I mean that the parent process has :
    > > signal(SIGCHLD, signal_handler_func()) call.
    > > I don't use threads explicitly at all.

    >
    > Do you call fork() from the signal handler, that is, from
    > signal_handler_func?


    yes


  9. Re: fork freeze

    On Apr 12, 4:18 am, "m4r3ck" wrote:

    > > Do you call fork() from the signal handler, that is, from
    > > signal_handler_func?


    > yes


    That is a recipe for disaster. If you need to get the same effect as
    this, either set a flag in the signal handler and notice it when
    you're done handling or block a thread on the signal and handle the
    signal synchronously. It requires significant expertise to do any
    "real work" from a signal handler that was invoked asynchronously.

    DS


  10. Re: fork freeze

    "David Schwartz" writes:
    > On Apr 12, 4:18 am, "m4r3ck" wrote:
    >
    >> > Do you call fork() from the signal handler, that is, from
    >> > signal_handler_func?

    >
    >> yes

    >
    > That is a recipe for disaster.


    fork is supposed to be async-signal safe.

  11. Re: fork freeze

    ok, I've solved it with the vfork call and replacing the message queue
    by something other
    thanks for help



  12. Re: fork freeze

    On 13 Apr, 11:15, "m4r3ck" wrote:
    > ok, I've solved it with the vfork call and replacing the message queue
    > by something other


    Just in case, the only thing you can do after vfork is exec.
    http://www.opengroup.org/onlinepubs/...ons/vfork.html


  13. Re: fork freeze

    On 4月13日, 下午4时00分, Rainer Weikusat wrote:
    > "David Schwartz" writes:
    > > On Apr 12, 4:18 am, "m4r3ck" wrote:

    >
    > >> > Do you call fork() from the signal handler, that is, from
    > >> > signal_handler_func?

    >
    > >> yes

    >
    > > That is a recipe for disaster.

    >
    > fork is supposed to be async-signal safe.


    Maxim has make the reason clear by quote from POSIX standard, see his
    reply on 12th.


  14. Re: fork freeze

    "Bin Chen" writes:
    > On 4月13日, 下午4时00分, Rainer Weikusat wrote:
    >> "David Schwartz" writes:
    >> > On Apr 12, 4:18 am, "m4r3ck" wrote:

    >>
    >> >> > Do you call fork() from the signal handler, that is, from
    >> >> > signal_handler_func?

    >>
    >> >> yes

    >>
    >> > That is a recipe for disaster.

    >>
    >> fork is supposed to be async-signal safe.

    >
    > Maxim has make the reason clear by quote from POSIX standard, see his
    > reply on 12th.


    What makes you think I was replying to that, considering that I
    didn't?

  15. Re: fork freeze

    On Apr 13, 1:00 am, Rainer Weikusat wrote:
    > "David Schwartz" writes:
    > > On Apr 12, 4:18 am, "m4r3ck" wrote:

    >
    > >> > Do you call fork() from the signal handler, that is, from
    > >> > signal_handler_func?

    >
    > >> yes

    >
    > > That is a recipe for disaster.

    >
    > fork is supposed to be async-signal safe.


    That's not the problem. The problem is that the child process is in a
    context in which only async-signal safe functions can be used.

    DS


+ Reply to Thread