Windows IPC analog to Linux Unix domain and Netlink sockets - linux

On Linux a fairly common method for IPC between userland processes and services is, for example, a socket interface (either Unix domain or netlink).
Simply -- What is the Windows analog of this and how do userland processes communicate with services?
To set the stage: Assume I have a background service running that monitors devices on a network. If I wanted to write a program to utilize the services provided by this service, what would be the common "Windows-way" of doing this?
If I am completely off-base here, what is the common way a Windows service may extend itself on the Windows OS so other processes may know it is actively listening for connections?

Windows has named pipes,
"A named pipe is a named, one-way or duplex pipe for communication
between the pipe server and one or more pipe clients. All instances of
a named pipe share the same pipe name, but each instance has its own
buffers and handles, and provides a separate conduit for client/server
communication. The use of instances enables multiple pipe clients to
use the same named pipe simultaneously."
https://msdn.microsoft.com/en-us/library/windows/desktop/aa365590%28v=vs.85%29.aspx

Related

Passing parameters between systemd services runtime

is it possible to pass parameters between services runtime? What I've already found is how to start services with variables and how to pass them parameters using an external file at run-time. However, I could not find information about exchanging data between services.
You're looking for an IPC mechanism. Systemd does not provide one because Linux already has quite a few.
The most common method is for a service to listen on a socket (usually an AF_UNIX socket in /run, but TCP is also an option, e.g. if you're writing in Java) and for other services to connect to it and submit or receive data. You can invent your own protocol, but practically any RPC system (such as gRPC or SunRPC or REST) that's built for network use will also work for local use, both across TCP and across AF_UNIX sockets.
D-Bus is one specific IPC system that systemd itself uses (which is also built on top of AF_UNIX sockets, but with a central "message bus" daemon), but it is not part of systemd. It will likely be available on any systemd-based distribution, however. D-Bus bindings are available for most programming languages.
Aside from AF_UNIX sockets, Linux also has several forms of "shared memory" and "message queue" systems (POSIX IPC and SysV IPC variants of each).

How two APP in embedded Linux communicate with each other normally

I have a main QT GUI App running in the embedded linux system. Now I need to create another APP which is to monitor a rotating knob position and send this information to the main QT GUI APP, wo what's the normal way for this two APP communicate?
There are many options, though using a pipe or socket is common. What you're looking for is Interprocess Communication.
QT has an interprocess communication abstraction that you can probably use to do this:
https://doc.qt.io/qt-5/ipc.html

Linux - options to establish IPC with second process

I am trying to study all the different ways I can find in order for a process on a linux machine to establish IPC with a second process (not a child) on the same machine. I did find that socket can be used given I know the path on file system the second process is listening to.
Is IPC communication with an second process possible in other ways ? I don't want the first process to know the pid/uid of the second process. The scenario is more towards communicating with an untrusted process, by a different author, on the same machine, but still have some information like where the socket in the second process is listening ?
Shared Memory and Sockets can be used for IPC communications between the processes that are not related to each other. Pipes can be used for IPC communications between the parent and child processes.
Shared memory is the fastest form of interprocess communication. In all other methods, the system calls copy the data from the memory area of one process to another process. The drawback of shared memory is, you need to implement synchronization methods to avoid race condition.
Sockets interfaces enables communication in a connection oriented way between the process across the network as well as locally. UNIX domain sockets provides local IPC using a known file path.
Possible ways:
Shared memory (shmget, shmctl, shmat, shmdt)
FIFO queues aka named pipes (mkfifo)
Message queues (msgget, msgsnd, msgrcv, msgctl)
Semaphores - for synchronization (semget, semctl, semop)
Hint:
Useful commands: ipcs, ipcmk, ipcrm
Also, you can use mmap POSIX standard call with flag MAP_SHARED specified. Here https://www.cs.purdue.edu/homes/fahmy/cs503/mmap.txt you can find an example of using it.

IPC using Linux pipe

I have doubt in using Linux Pipes for IPC. My question is
Can Linux pipes can be used to communicate between the processes running on different machines?.
Thanks,
No, you can't use only pipe to communicate between different machines, because pipe is defined as local machine communication method (IEEE standard says that it creates two file descriptors in current process. Descriptors usually can't be send to other machine, only inherited from parent or passed via local machine sockets).
But you can try to use pipe to some external socket program, like netcat, which will resend all data over tcp socket, and remote netcat will replay it back into the program.
And if you are developing some application, it can be better to use tcp sockets directly.
PS: The IPC - Inter-process communication - AFAIK means communications between different processes on one (same) machine (linux IPC from Linux Programmer's Guide 1995).
PPS: If sockets are hard to work with them directly, you may choose some Message Passing library or standard. For example MPI standard (OpenMPI, MPICH libraries) is often used to communicate between many machines in tightly-coupled computing clusters, and there are some popular interfaces like RPC (Remote procedure call, several implementations) or ZeroMQ
Pipe is only used for communication between related process on the same host (eg. parent and child process).

Communication between two Perl processes in a daemon / client setup. What is it called?

I'm writing a daemon that interfaces with a USB device (an Arduino). This daemon is continuously aware of the current state.
Now I want to be able to interface with this daemon through a client program, also to be written in Perl. This client must be able to query the daemon for its current state and it must be able to update the daemon with settings.
I'm on Linux (x86_64)
I don't want to use an intermediate file and preferably simultaneous queries are easily implemented.
What is the name of such a mechanism? What Perl libraries can I use or should I avoid? What should I DuckDuckGo for?
Probably, you need to implement an event loop to allow doing the tasks of your USB device communication and serve information to the new interface. This concept will change the way you solved the problem, but I think is the better approach.
You can search at CPAN for modules like POE and AnyEvent
The idea is to build an event loop that handles a TCP socket in order to send & receive information from te interface

Resources