Solved

LINUX and interprocess communication

Posted on 2001-09-17
9
201 Views
Last Modified: 2010-04-21
Hi,
Can somebody give me some details how following situation can be handled in Linux (I need to programm it in C)?
Process A needs to inform process B about something that happened in process A. In Windows one can use window message, what in Linux (Is there some sample code?).
How can one retrieve from B the information set due to A?
Thx.
0
Comment
Question by:jlsjls
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
9 Comments
 
LVL 5

Expert Comment

by:garboua
ID: 6488264
you can use global memory methods such as mailBoxes, and struct,
you can use signals,
use sockets, client server methods.
0
 
LVL 8

Expert Comment

by:mnashadka
ID: 6488701
You can also use named semaphores to help with that (if your waiting process can go into a wait).  Use the sem_wait to lock the semaphore and sem_post to unlock the semaphore.  Process B can go into a sem_wait, which will wait for Process A (or some other process) to perform a sem_post.  But of course there are many ways to do this (as garboua said).
0
 
LVL 51

Accepted Solution

by:
ahoffmann earned 38 total points
ID: 6488750
you can use sockets
you can use shared memory
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 3

Assisted Solution

by:superschlonz
superschlonz earned 37 total points
ID: 6489045
You could also use named pipes.
Create it with 'mknod p name' where name is a filename. After that you use it like a file.
A opens it for writing an writes a message into it, B opens it for reading and waits for a message.
0
 

Expert Comment

by:johanhz
ID: 6489815
I am relatively new to linux programming, and a collegue of jlsjls, so jlsjls, don't accept my comments as an answer.

what we basically want to do is the following :

Program A receives some input (in our case from a serial port)
Program A must signal Program B that some input has been received
If Program B receives the signal, it then gets the data from a Shared library.

Program A receives --> place the data in shared memory of the shared library --> Signal PRogram B that something was received --> Program B gets the data from the shared library.

I think we can do with
Message queue to share memory of the so with program A
use kill() to signal Program B, program B uses Signal() to receive the signal. Program B then call's an exported function of the so to get the data.

It this a correct method of working?

JOHan.
0
 
LVL 3

Expert Comment

by:superschlonz
ID: 6490153
if the data is small (up to 1kB) it's easier to use named pipes, you would not need SHM and signals, only open, read and write. With ls you can see if data is in the pipe.

If you plan to to extend the system later (for ex. more processes communicating with each other) then it's probably better to use SHM and protect it with a semaphor (locking it before using the SHM).
I think you need a semaphor even if you use signals because a could overwrite the shared memory when B is reading it.
0
 
LVL 5

Expert Comment

by:garboua
ID: 6493884
well, you can create two threads, one to watch the serial port for stream, and one to program B that will do the processing of data, I think that what U want.
You can use semaphores to control the two, have them wait on each other,  you can create a shared memory buffer, or a specific strucutre and pass its address to both threads, semaphore will guarantee that processes won't mix up data.  
or three, one to scan port and copy it to a waiting QuE, which is your second, and third to process.
0
 
LVL 20

Expert Comment

by:jmcg
ID: 9918138
No comment has been added lately, so it's time to clean up this TA.
I will leave the following recommendation for this question in the Cleanup topic area:

Split: ahoffmann {http:#6488750} & superschlonz {http:#6490153}

Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

jmcg
EE Cleanup Volunteer
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
The purpose of this article is to fix the unknown display problem in Linux Mint operating system. After installing the OS if you see Display monitor is not recognized then we can install "MESA" utilities to fix this problem or we can install additio…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Sometimes it takes a new vantage point, apart from our everyday security practices, to truly see our Active Directory (AD) vulnerabilities. We get used to implementing the same techniques and checking the same areas for a breach. This pattern can re…

634 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question