Welcome to the most active Linux Forum on the web.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 02-19-2005, 11:32 PM   #1
Registered: Feb 2005
Posts: 77

Rep: Reputation: 15
how to use fork/pipe to decrement a global varialbe Y and exit when Y is 0

suppose I have the following already:

#include <stdio.h>
#include <stdlib.h>

int Seats_Available=36;

void thread(int id)
while (1)

if (Seats_Available <=0)

if ( rand()%4==0 && Seats_Available < 36)
printf("Agent %d cancel a seat. ", id);
printf("Seats available: %d \n", Seats_Available);

printf("Agent %d books a seat. ", id);
printf("Seats available: %d \n", Seats_Available);


How do I write use fork, pipe to update the Seats_Available, and finishes when Seats_Available is 0?
Please give me some hint.
Old 02-19-2005, 11:33 PM   #2
Registered: Feb 2005
Posts: 77

Original Poster
Rep: Reputation: 15
I need 6 threads to update the global variable "Seats_Available".


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
difference between exit 1 and exit kushalkoolwal Programming 6 10-20-2005 03:56 PM
pam_mount login count doesn't decrement beaucoup Linux - Security 0 08-04-2005 11:08 PM
Sockets, pthread, pipe, and fork -- a messaging server ggravarr Programming 3 06-28-2005 02:39 PM
Wierd behaviour using fork() and pipe() cybermix Programming 4 01-08-2004 03:44 AM
over-fork luzi82 Linux - Newbie 2 01-02-2004 06:55 AM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:18 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration