Solved

LINUX and interprocess communication

Posted on 2001-09-17
9
193 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
9 Comments
 
LVL 5

Expert Comment

by:garboua
Comment Utility
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
Comment Utility
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
Comment Utility
you can use sockets
you can use shared memory
0
 
LVL 3

Assisted Solution

by:superschlonz
superschlonz earned 37 total points
Comment Utility
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
6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

 

Expert Comment

by:johanhz
Comment Utility
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
Comment Utility
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
Comment Utility
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
Comment Utility
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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

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…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

763 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

Need Help in Real-Time?

Connect with top rated Experts

6 Experts available now in Live!

Get 1:1 Help Now