How to communicate between two processes

This is a discussion on How to communicate between two processes within the Linux Programming forums, part of the Platform Specific Boards category; Yes, in that select really shouldn't be in the struct in the first place, since it's not part of the ...

  1. #16
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    Yes, in that select really shouldn't be in the struct in the first place, since it's not part of the actual address book data. Pass an int. (In this case, "pass" means "put in the first part of shared memory" I would guess. Hooray for re-developing the idea of a stack!)

  2. #17
    Registered User
    Join Date
    Sep 2011
    Posts
    23
    I did not get it. How to put it in the first part of shared memory.

  3. #18
    Registered User
    Join Date
    Nov 2010
    Location
    Long Beach, CA
    Posts
    5,498
    The shared memory is just a big chunk of memory both processes can write to, like a piece of paper shared between two people. Both people need to know what is on each line of the paper. You start by putting select on "the first line", or right at the beginning of the block of shared memory. Your array a will start on "the second line". In your code, shared_memory, which is the value returned by shmat(), is the starting address of your block of shared memory. For example:
    Code:
    memcpy(shared_memory, &select, sizeof(select));  // store select at the beginning of shared_memory
    memcpy(shared_memory + sizeof(select), a, sizeof(a));  // store a at the first spot after select

  4. #19
    Registered User
    Join Date
    Sep 2011
    Posts
    23
    @tabstop and @anduril462. Thank you guys. Now my doubt is cleared.

Page 2 of 2 FirstFirst 12
Popular pages Recent additions subscribe to a feed

Similar Threads

  1. how to communicate with the web server
    By nadeem athani in forum Linux Programming
    Replies: 1
    Last Post: 03-09-2011, 08:11 AM
  2. Get .cpp and .h files to communicate...
    By yaya in forum C++ Programming
    Replies: 6
    Last Post: 11-24-2008, 11:45 PM
  3. How to communicate with com port?
    By alan85 in forum C++ Programming
    Replies: 7
    Last Post: 12-10-2004, 09:56 PM
  4. Getting two programs to communicate
    By Thantos in forum Windows Programming
    Replies: 4
    Last Post: 08-27-2003, 07:39 AM
  5. can't get MFC to communicate with itself
    By drb2k2 in forum C++ Programming
    Replies: 2
    Last Post: 04-04-2003, 03:06 PM

Tags for this Thread


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