Find the answer to your Linux question:
Results 1 to 3 of 3
First i want to run a process in the background and as i have read to do so i have to exit its father so it will run in the ...
Enjoy an ad free experience by logging in. Not a member yet? Register.
  1. #1
    Just Joined!
    Join Date
    Oct 2010
    Posts
    1

    Process Questions in C (fork and critical region)


    First i want to run a process in the background and as i have read to do so i have to exit its father so it will run in the back

    i first wrote this code

    child_identity=fork();
    if (child_identity>0)
    {
    exit(0);
    }

    but just as the child runs it runs the whole code again and makes an unwanted fork

    In the same way i have a problem understanding the critical sections solution of Peterson ,this is the code

    enter_region(process)
    {
    other=1-process;
    interested[process]=TRUE;
    turn=process;
    while(turn==process&&interested[other]==TRUE)
    }

    when you enter the critical region
    and

    leave_region(process)
    {
    interested[process]=FALSE;
    }

    the process value entered in both functions is variable and based to the process that calls this function but the only number that is like this is tha number returned by fork that is 0 to the child and different to others ,still to produce such a value before all must be a fork and so all child processes will call a fork too and will ruin the code.Is there a solution.
    Last edited by fleshwound; 10-21-2010 at 02:00 AM.

  2. #2
    Just Joined!
    Join Date
    Dec 2009
    Location
    Maryland, USA
    Posts
    82

    Improve your thread title

    The language you're programming in is probably obvious to some once they open your topic, but it would be even better if you included that info in the thread title, perhaps even repeating the info in the problem description/question.

    Good luck!

  3. #3
    Linux Guru Rubberman's Avatar
    Join Date
    Apr 2009
    Location
    I can be found either 40 miles west of Chicago, in Chicago, or in a galaxy far, far away.
    Posts
    11,508
    This is a school exercise or homework problem?
    Sometimes, real fast is almost as good as real time.
    Just remember, Semper Gumbi - always be flexible!

Posting Permissions

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