Professional Web Applications Themes

Question about execution of threads and parent/child processes - UNIX Programming

Hello everybody, I have a question about how things are executed (I do realize it's up to the scheduler in the OS, in this case Linux, Red Hat 9) in multi-threaded apps and such. I have an application where I'm dumping > 16mb of data on to a file descriptor and the network interface card (using the socket() connect() and send() calls), that is 16mb on both, total of > 32mb. I have written two different versions of the program because I was concerned that my first attempt at writing multi-threaded apps wasn't doing what I thought it was. In ...

  1. #1

    Default Question about execution of threads and parent/child processes

    Hello everybody,

    I have a question about how things are executed (I do realize it's up
    to the scheduler in the OS, in this case Linux, Red Hat 9) in
    multi-threaded apps and such.

    I have an application where I'm dumping > 16mb of data on to a file
    descriptor and the network interface card (using the socket()
    connect() and send() calls), that is 16mb on both, total of > 32mb.

    I have written two different versions of the program because I was
    concerned that my first attempt at writing multi-threaded apps wasn't
    doing what I thought it was. In the first, the multi-threaded
    version, main() opens a thread that writes the data on to the network,
    and main() dumps the data to /dev/lp0.

    In the other version, I use fork() to create a child that does the
    network stuff while the parent does the /dev/lp0 stuff. I've written
    some basic status stuff in to the program, by basic I mean that at
    intervals some status strings are printed to stdout in the form of
    fprintf(stdout, "child/thread still kicking").

    The deal is though, I don't think that the execution is happening in
    paralle in either case. For instance, when either is run, all the
    child/thread1 stuff is printed to stdout first, then the
    parent/thread0 stuff after that. I would have expected that the
    programs would be executing in a parallel manner. Parent/thread0 for
    a while, child/thread1 for a while, parent/thread0 for a while, ...
    etc.

    Any suggestions?

    Andy
    Andrew Guest

  2. #2

    Default Re: Question about execution of threads and parent/child processes

    Perhaps I/O operations tend to want to run til completion, and not share
    the cpu, unless the operation is VERY long.

    Andrew Falanga wrote: 

    Joseph Guest

  3. #3

    Default Re: Question about execution of threads and parent/child processes

    You might want to verify that this is not an oddity of behaviour caused
    by both threads/processes dumping to stdout/stderr on your controlling
    terminal? Try sending the status info to two different files? Also,
    How quickly is 16M written? i.e. can 16M be written before a the new
    thread/process has a chance to get up and running? Try the same test
    with 100's of MBytes and see if the contect swtiching is more apparent.

    In a 100 Mb/s network connection, you may be able to dump 10 MBytes/s.

    Cheers.

    Andrew Falanga wrote: 

    --
    ================================================== ======================
    Missaka Wijekoon (a.k.a. Misk)
    Sr. Software Engineer
    RemoveToSend.com

    VillageEdocs
    http://www.villageEdocs.com
    ================================================== ======================

    Missaka Guest

  4. #4

    Default Re: Question about execution of threads and parent/child processes


    "Andrew Falanga" <com> wrote in message
    news:google.com... 
    [snip..] 

    Maybe use fprintf(stderr,"child/thread still kicking"), note the "stderr"
    instead of "stdout", since stderr is unbuffered and will write immediately.

    Regards,

    Mike Chirico


    Mike Guest

Similar Threads

  1. Parent/Child relations - Trying to access child control for save
    By tnt_lu@hotmail.com in forum ASP.NET Data Grid Control
    Replies: 0
    Last Post: April 15th, 12:50 PM
  2. Replies: 31
    Last Post: December 9th, 11:06 PM
  3. Ruby, Threads and Processes
    By ts in forum Ruby
    Replies: 2
    Last Post: July 5th, 08:52 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

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 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139