Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

LINUX and interprocess communication

Posted on 2001-09-17
9
Medium Priority
?
203 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 152 total points
ID: 6488750
you can use sockets
you can use shared memory
0
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.

 
LVL 3

Assisted Solution

by:superschlonz
superschlonz earned 148 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

Fill in the form and get your FREE NFR key NOW!

Veeam® is happy to provide a FREE NFR server license to certified engineers, trainers, and bloggers.  It allows for the non‑production use of Veeam Agent for Microsoft Windows. This license is valid for five workstations and two servers.

Question has a verified solution.

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

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…
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…
We’ve all felt that sense of false security before—locking down external access to a database or component and feeling like we’ve done all we need to do to secure company data. But that feeling is fleeting. Attacks these days can happen in many w…

688 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