I've written a TCP server using IO::Socket::INET that opens a socket and listens for new connections. When a connection is accepted, it calls fork() and the child process becomes the "control" process that handles the subsequent input from the filehandle.

Whenever the "control" process reads from the socket, it forks another child, which does some work and then writes a response to the client. What this means is that there may be several separate processes writing to the same filehandle.

The server performs well for awhile, but eventually it gets into a state where it will spawn a "control" process for a new connection, but when the control process spawns in response to a write from the client, the subsequent child process encounters a Bus Error and dies.

The truss output looks like this:

$ truss -pf 18714 18714: accept(3, 0xFFBEEC4C, 0xFFBEEC5C, 1) (sleeping...) 18714: accept(3, 0xFFBEEC4C, 0xFFBEEC5C, 1) = 4 18714: fcntl(4, F_SETFD, 0x00000001) = 0 18714: fork() = 7531 7531: fork() (returning as child ...) = 18714 7531: getpid() = 7531 [18714] 18714: write(1, " 1 8 7 1 4 c o n n e c".., 26) = 26 18714: getcontext(0xFFBEE798) 7531: write(1, "\t 7 5 3 1 c o n t r o".., 27) = 27 18714: getcontext(0xFFBEE660) 18714: close(4) = 0 18714: llseek(4, 0, SEEK_CUR) Err#9 EBADF 18714: close(4) Err#9 EBADF 7531: fstat64(4, 0xFFBEEAA0) = 0 18714: write(1, "\t 1 8 7 1 4 w a i t i".., 33) = 33 7531: brk(0x00B7E000) = 0 7531: ioctl(4, TCGETA, 0xFFBEEA2C) Err#22 EINVAL 7531: read(4, " F r T ; @ 1 8 | $ 9 | S".., 8192) = 215 7531: time() = 1077734297 7531: write(1, " 7 5 3 1 1 0 7 7 7 3 4".., 319) = 319 18714: getcontext(0xFFBEE798) 7531: fork() = 7533 7533: fork() (returning as child ...) = 7531 7533: getpid() = 7533 [7531] 7531: write(1, " 7 5 3 1 f o r k e d ".., 17) = 17 7533: Incurred fault #5, FLTACCESS %pc = 0x00029F18 7533: siginfo: SIGBUS BUS_ADRALN addr=0x47454E35 7533: Received signal #10, SIGBUS [default] 7533: siginfo: SIGBUS BUS_ADRALN addr=0x47454E35 7531: time() = 1077734297 7531: write(1, " 7 5 3 1 1 0 7 7 7 3 4".., 114) = 114 7531: Incurred fault #5, FLTACCESS %pc = 0x00029F18 7531: siginfo: SIGBUS BUS_ADRALN addr=0x47454E35 7531: Received signal #10, SIGBUS [default] 7531: siginfo: SIGBUS BUS_ADRALN addr=0x47454E35 7531: *** process killed *** 18714: Received signal #18, SIGCLD, in accept() [caught] 18714: siginfo: SIGCLD CLD_KILLED pid=7531 status=0x000A 18714: accept(3, 0xFFBEEC4C, 0xFFBEEC5C, 1) Err#91 ERESTAR +T 18714: waitid(P_ALL, 0, 0xFFBEE548, WEXITED|WTRAPPED) = 0 18714: sigaction(SIGCLD, 0xFFBEE440, 0xFFBEE4C0) = 0 18714: setcontext(0xFFBEE930) 18714: getcontext(0xFFBEE798) 18714: getcontext(0xFFBEE660) 18714: write(1, "\t 1 8 7 1 4 w a i t i".., 33) = 33 18714: getcontext(0xFFBEE798) 18714: accept(3, 0xFFBEEC4C, 0xFFBEEC5C, 1) (sleeping...) 7533: *** process killed ***

Any kind souls out there have advice on what may be causing this and how to fix it? Thanks, Brian


In reply to Forking server getting Bus Errors by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.