Professional Web Applications Themes

Multiple instance of process - memory conflicts - Sun Solaris

I wonder if anybody could shed some light on a problem I am encountering. I have written a program in C that runs on Solaris 2.8. At busy times of the day there may be multiple instances of it running (5-10), each process taking approx. 3 seconds to complete. Each instance of the program basically fetches data from a Oracle database (using Remedy ARS API routines) and stores it in a user defined structure that I have defined as a global variable. The problem I encounter is when multiple instances of the program are running. Often I find that the ...

  1. #1

    Default Multiple instance of process - memory conflicts

    I wonder if anybody could shed some light on a problem I am
    encountering.

    I have written a program in C that runs on Solaris 2.8. At busy times
    of the day there may be multiple instances of it running (5-10), each
    process taking approx. 3 seconds to complete.

    Each instance of the program basically fetches data from a Oracle
    database (using Remedy ARS API routines) and stores it in a user
    defined structure that I have defined as a global variable. The
    problem I encounter is when multiple instances of the program are
    running. Often I find that the data in memory being held in one
    process is mixed up with the data in memory of another.

    A simplified example could be:

    process instance 1 fetches data from record NA1234 and stores record
    id in a string variable str1:

    process instance 2 fetches data from another record NA9999 and stores
    record
    id also in a string variable str1:

    However when I check the value of var1 in process instance 2, it
    sometimes may say NA9999 (which would be correct) but other times it
    may say NA1234 (ie. it is sharing the memory space of process 1),
    especially when the processes are running in parallel.

    Can this phenomena be attributed to global variables - if so changing
    to a local instance would relieve this?

    Any assistance greatly appreciated.

    -- Shuaib
    Shuaib Guest

  2. #2

    Default Re: Multiple instance of process - memory conflicts

    com (Shuaib) writes:
     

    Are these processes using shared memory? If not, it's impossible to
    get a mixup. If they are using shared memory, you will get that sort
    of problems, unless you do something to prevent it.

    --
    Måns Rullgård
    sf.net
    Måns Guest

  3. Moderated Post

    Default Re: Multiple instance of process - memory conflicts

    Removed by Administrator
    Nils Guest
    Moderated Post

  4. #4

    Default Re: Multiple instance of process - memory conflicts

    Shuaib wrote:
     

    My guess is you've done something like this:

    (1) open Oracle connection in parent process
    (2) fork()
    (3) do Oracle query in children

    That may not be a valid way to use the Oracle db client code.
    I would try doing this instead:

    (1) fork()
    (2) open Oracle connection in child
    (3) do Oracle query in child

    I'm not an Oracle expert, I am only thinking of what might happen
    if two instances of the client code are sharing the same initial
    values in their data structures and are sharing the TCP connection.

    Hope that helps.

    - Logan

    Logan Guest

  5. #5

    Default Re: Multiple instance of process - memory conflicts

    Logan Shaw wrote: 
    >
    >
    > My guess is you've done something like this:
    >
    > (1) open Oracle connection in parent process
    > (2) fork()
    > (3) do Oracle query in children
    >
    > That may not be a valid way to use the Oracle db client code.
    > I would try doing this instead:
    >
    > (1) fork()
    > (2) open Oracle connection in child
    > (3) do Oracle query in child
    >
    > I'm not an Oracle expert, I am only thinking of what might happen
    > if two instances of the client code are sharing the same initial
    > values in their data structures and are sharing the TCP connection.[/ref]

    Extremely likely.

    I have found (painfully!) that even this leads to trouble:

    (1) Connect to Oracle in parent
    (2) fork
    (3) Do nothing related to Oracle in child
    (4) Exit child

    or this:

    (3) Do nothing related to Oracle in parent
    (4) Exit parent

    Because the Oracle client runtime registers an atexit, just exiting the
    process becomes akin to an Oracle request!

    Since there does not seem to be any way to unregister an atexit handler,
    the only thing that works is to have *NO* Oracle connection at all while
    you fork. (There may be something in the most recent Oracle OCI API to
    cirvent that problem, but I haven't found it yet)
     


    --
    Michel Bardiaux
    Peaktime Belgium S.A. Bd. du Souverain, 191 B-1160 Bruxelles
    Tel : +32 2 790.29.41

    Michel Guest

  6. #6

    Default Re: Multiple instance of process - memory conflicts


    "Michel Bardiaux" <be> wrote in message
    news:be...
     

    That's why the child should not call 'exit'. This same problem exists
    with stdio streams.

    DS


    David Guest

Similar Threads

  1. Replies: 0
    Last Post: February 1st, 09:48 AM
  2. Multiple instance of process - memory conflicts
    By Shuaib in forum UNIX Programming
    Replies: 5
    Last Post: October 8th, 05:11 PM
  3. Replies: 0
    Last Post: June 27th, 05:32 PM
  4. Replies: 1
    Last Post: June 26th, 04:00 AM

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