Click here to Skip to main content
15,891,184 members
Please Sign up or sign in to vote.
1.00/5 (3 votes)
See more:
Hi,

I am working on multi process environment on embedded Linux Kernel.

How can I make all of my elfs to listen the console without blocking other elfs.

For example:

app1.elf -> call getchar() or similar
app2.elf -> call getchar() or similar
app3.elf -> call getchar() or similar

When I press the say 'a' from the keyboard I want all applications to receive the typed key.

Current behaviour is that if input is captured by app1.elf the others gets nothing.

Any hint will highly be appreciated.

Thanks in advance.
Posted
Updated 8-Oct-13 3:16am
v2
Comments
pasztorpisti 8-Oct-13 9:40am    
The first thing that comes to my mind is that you are trying to solve a problem in the wrong way. If you still insist on solving your problem this way without sharing the actual problem with us then I think sending the input stream with pipes to the other processes is the way to go, but even in this case buffering and blocking pipe write operations can be a problem depending on the actual scenario.
Sergey Alexandrovich Kryukov 8-Oct-13 11:29am    
Absolutely, well said. This is like inserting a door key in a wrong lock. This is not a main problem, the bigger problem is that when you try to help, some will say: "just help me to push it harder". :-)
—SA
pasztorpisti 8-Oct-13 11:46am    
:-) :-) :-) This is quite typical!
Sergey Alexandrovich Kryukov 8-Oct-13 11:36am    
However, OP wanted some hints, so I provided some hint, please see my answer.
As the ultimate goals of this are not explained, this is all... :-)
—SA

1 solution

Please see the encouraging comments to the question. :-)

It would be hard to help as you apparently are trying to push some misconceptions, but we don't know your ultimate goals which only would make sense to discuss. So, all you can get now is some hints. Here:
http://en.wikipedia.org/wiki/Multithreading_%28software%29#Multithreading[^],
http://www.linuxjournal.com/article/3138[^],
http://en.wikipedia.org/wiki/Inter-process_communication[^],
http://en.wikipedia.org/wiki/Socket_API[^],
http://www.linuxhowtos.org/C_C++/socket.htm[^].

—SA
 
Share this answer
 
Comments
pasztorpisti 8-Oct-13 11:49am    
+5. If the solution is linux only then I would advice using multiplexing (select) with nonblocking file handles instead of multithreading. Both are difficult to use but learning/using select tends to be easier for most programmers. Sockets is indeed a good replacement for pipes and its more flexible in exchange for a bit more lines of code.
Sergey Alexandrovich Kryukov 8-Oct-13 12:19pm    
Thank you, and — could you explain a bit more on multiplexing select? Could it make an alternative question? (I know, the hassle is not knowing OP's goals...)

As to the sockets: I'm sure you know that sockets, historically, was developed as a pure IPC facility, networks came up later, as the generalization of the socket technology. And, by the way, performance is not compromised if one uses sockets as IPC.

—SA
pasztorpisti 8-Oct-13 12:30pm    
I remember that I had to install separate drivers on windows to force loopback connections to go through the network stack in order to be able to capture it. Loopback connections are indeed optimized and work much like pipes. Thinking it over again, multithreading is probably needed (and also buffering) if we want to create a transparent solution that runs in the background while the app uses its original code calling stdio functions (like getchar). Without threading the app code should actively handle the interprocess communication too that would be less clear.
Sergey Alexandrovich Kryukov 8-Oct-13 12:49pm    
This is what I though. Generally, I think that the attempts to work around threading by using all kinds of asynchronous APIs is counter-productive. Behind the scene, it is still threading but:
1) threading development is generally linear, with rare synchronizations; it makes the logic simpler;
2) threading approaches is general: you learn them once and use over and over; asynchronous APIs depend on application, you have to learn them separately for each technology.
3) due to more universal character of threading approaches, you can theoretically analyze code using general approaches (such as Petri net); it's good to understand that threading problems are not well fixed by testing and debugging, theoretical correctness is critical.

—SA
pasztorpisti 8-Oct-13 13:11pm    
Absolutely true. Multithreading is basically a possible implementation of an async task, and multithreading is always at hand while async APIs are rarely available and even if they are present the interface is always different as you said.
Still, for some reason thread lifetime management and inter-thread communication seems to be something that is impossible to understand for most. Often, the only synchronization point should be only a message queue, sometimes 1-2 shared "databases" and thats it but people like pain in the ass and force themselves to use shared variables... Thread lifetime: maybe the simplest solution that is viable in most cases is precreating threads at startup and deleting them at exit. Instead of this they find very exotic ways to spawn/finish threads.
I've just recalled the last gui+thread related question on CP, the guy kept posting comments/messages to me for weeks relating a very simple background worker thread and he was unable to put together a good solution while step by step instructions were available for him from the very beginnings.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900