Thread: can someone shed some light

  1. #1

    can someone shed some light

    am currently reviewing old tests in order to prepare myself for my final exam.

    i will be the first to admit it: i suck at fork()ing and piping . i suck at them b/c i have a hard time understanding their behavior.

    so i have been reivewing like a fiend and feel comfortable with fork()ing and/or pipe()ing, so long as the two are not combined.

    so with that said - can someone explain how i could approach a problem such as this:
    Write a C program which will create a total of 37 processes all of which will have their own separate pipe. i.e. all processes will be able to write to all other processes but each processes will only read from its own pipe. In addition, each process will have an assigned index, 0...36.

    Each processes will check it's pid and if its pid is even, it will write its pid to each of the processes with even indicies, while, if its pid is odd, it will write its pid to each of the processes with odd indices (but no process writes to itself). Then each process will read all the messages written to its pipe and print on stdout, for each message, a line similar to:
    Procedss 35894 heard from process 35992
    Be careful that your code doesn't hang!
    mind you this isn't the only question that i am having difficulty with, but i don't wanna seem like a major whine bag. but if someone could point out which way the light is at, i would appreciate it.
    DrakkenKorin

    Get off my Intarweb!!!!

  2. #2
    ATH0 quzah's Avatar
    Join Date
    Oct 2001
    Posts
    14,826
    Use an array of pipes, as shown here.

    Quzah.
    Hope is the first step on the road to disappointment.

  3. #3
    i pretty much figured i needed an array of pipes - int fdp[37][2];

    however, where i have the most problems, is in connecting the ends of the pipes to the right place, esp when the process has to write to ALL OTHER processes. i'm familiar with writing to another process, or to STDIN or STDOUT, but i am not at all familiar with writing to 36 other processes. i'm sure there's gonna be a for loop in there, including a while to read.

    also just noticed my baldspot is more pronounced now...
    DrakkenKorin

    Get off my Intarweb!!!!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Critique my lighting model.
    By psychopath in forum Game Programming
    Replies: 4
    Last Post: 08-12-2006, 06:23 PM
  2. geometry won't display!?
    By psychopath in forum Game Programming
    Replies: 17
    Last Post: 09-21-2004, 10:10 AM
  3. How many forums members to change a lightbulb.
    By adrianxw in forum A Brief History of Cprogramming.com
    Replies: 21
    Last Post: 01-01-2004, 08:31 PM
  4. Easy way to light an orthogonal display
    By frenchfry164 in forum Game Programming
    Replies: 0
    Last Post: 05-05-2003, 05:19 PM
  5. A Common Scientific Belief
    By DavidP in forum A Brief History of Cprogramming.com
    Replies: 10
    Last Post: 03-29-2002, 05:54 PM