multiprocessing question

This is a discussion on multiprocessing question within the C Programming forums, part of the General Programming Boards category; well i'm sorta new to muliprocessing to the point were i can use fork() two different ways. One way is ...

  1. #1
    Registered User
    Join Date
    Aug 2009
    Posts
    192

    multiprocessing question

    well i'm sorta new to muliprocessing to the point were i can use fork() two different ways. One way is to have one main program and have it fork to do different processes. The second way is to have 2 mains and one process just forks into the second main process have both mains run simutaneously. But I wanted to use the second method with two mains, but I dont know how to interproccess communicate the info to each other like if i was sending in an array from one process to another how to do this.

  2. #2
    spurious conceit MK27's Avatar
    Join Date
    Jul 2008
    Location
    segmentation fault
    Posts
    8,300
    "Interprocess communication" is something you have to set up between the processes, using a pipe or socket to send messages back and forth.

    If you want to share variable directly, you need to use the pthread library or something similar.
    C programming resources:
    GNU C Function and Macro Index -- glibc reference manual
    The C Book -- nice online learner guide
    Current ISO draft standard
    CCAN -- new CPAN like open source library repository
    3 (different) GNU debugger tutorials: #1 -- #2 -- #3
    cpwiki -- our wiki on sourceforge

  3. #3
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,352
    Quote Originally Posted by kiros88 View Post
    well i'm sorta new to muliprocessing to the point were i can use fork() two different ways. One way is to have one main program and have it fork to do different processes. The second way is to have 2 mains and one process just forks into the second main process have both mains run simutaneously. But I wanted to use the second method with two mains, but I dont know how to interproccess communicate the info to each other like if i was sending in an array from one process to another how to do this.
    If the two processes are going to communicate a lot, you should consider using threads instead of separate processes. If processes are really what you want, the usual way of communicating data between them is pipes.
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  4. #4
    Super Moderator
    Join Date
    Sep 2001
    Posts
    4,913
    You can use pipes (there are various types), shared memory, signals, etc... What method you use depends on your needs. I learned from this tutorial, and other references are abundant: 6 Linux Interprocess Communications

  5. #5
    Registered User
    Join Date
    Aug 2009
    Posts
    192
    Well I'm developing a network program so I'm not really sure if two processes are better then threads but I just thought since I have a seperate process taking in network frames and then a seperate one using the frame for its own application would it be smarter to just do that all in one process with multiple threads?

  6. #6
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,267
    If I understand you correctly, then yes it would be better to use 1 process with multiple threads. You have 1 thread receiving packets of the wire, and another thread processing those packets. It's a pretty common design pattern if you are not using non-blocking sockets or select().
    bit∙hub [bit-huhb] n. A source and destination for information.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Debugging question
    By o_0 in forum C Programming
    Replies: 9
    Last Post: 10-10-2004, 05:51 PM
  2. Question about pointers #2
    By maxhavoc in forum C++ Programming
    Replies: 28
    Last Post: 06-21-2004, 12:52 PM
  3. Question...
    By TechWins in forum A Brief History of Cprogramming.com
    Replies: 16
    Last Post: 07-28-2003, 09:47 PM
  4. Question about linked lists.
    By cheeisme123 in forum C++ Programming
    Replies: 6
    Last Post: 02-25-2003, 12:36 PM
  5. Question, question!
    By oskilian in forum A Brief History of Cprogramming.com
    Replies: 5
    Last Post: 12-24-2001, 12:47 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21