Find the answer to your Linux question:
Results 1 to 4 of 4
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1

    Can anyone help with this?

    Hello!Can anyone help me with this:
    I'm creating N processes with this code:

    for (i=0; i<N; i++) {
    child_pid = fork();
    switch(child_pid) {
    case -1:
    case 0: /* we're at child process. */
    default: /* we're at parent process. */
    Every process i create calls this function:

    void do_child(int sem_id)

    for (i=0; i<Y; i++) {

    each one enters in vafeio function :the critical section Y times each.
    When i create the N processes i'm putting their pids in an array:
    the first process which is made has her pid in array[0] e.t.c
    My problem is that when a process is in the critical section i don't know in which place of the array her pid is.
    Can anyone help with this

  2. #2
    Linux Guru lakerdonald's Avatar
    Join Date
    Jun 2004
    St. Petersburg, FL
    In the future, please encode any code in [code] tags.

  3. #3
    I think we're (I'm) going to need more information on this. Where's your array? Do you think the child array is visible to the parent, or the child can see the parent's array (hint: they can't)?

  4. $spacer_open
  5. #4
    finally i found a soluton for this myself.I used a variable called number and i initialised it in -1.Inside the for loop:for(i=0;i<n;i++) the first thing i wrote was: number++; .So every process i create has it's own number.The first has number=0; and the last number=n-1.It worked for me.In this way i knew which process from my array was in the critical section.
    Thanks for your interest!

Posting Permissions

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