ipc

Communicating with a running process

白昼怎懂夜的黑 提交于 2019-12-09 19:00:47
问题 We have: A Python based server (A) A running command-line application (on the same Linux machine) which is able to read stdin , computes something and provides the output into stdout (B) What is the best (most elegant) way how to send an input from (A) to stdin of (B), and wait for an answer from (B), i.e read its stdout ? 回答1: As @Deestan pointed subprocess,module, is an elegant and proven one. We use subprocess a lot when we have to run commands from python. Ours mostly involves running a

Using mutexes/semaphores with processes

拥有回忆 提交于 2019-12-09 18:24:08
问题 Almost all the code and tutorials that I have read online so far involve using mutexes and semaphores for synchronisation amongst threads. Can they be used to synchronise amongst processes? I'd like to write code that looks like this: void compute_and_print() { // acquire mutex // critical section // release mutex } void main() { int pid = fork(); if ( pid == 0 ) { // do something compute_and_print(); } else { // do something compute_and_print(); } } Could someone point me towards similar

[翻译]Android接口定义语言 (AIDL)

孤人 提交于 2019-12-09 15:00:55
AIDL(Android接口定义语言)与你可能使用过的其它的IDLs是类似的。它允许你定义客户端与service协调一致的编程接口,以便于彼此之间使用进程间通信(IPC)机制进行通信。在Android上,一个进程通常不能访问另一个进程的内存。可以说,它们需要把它们的对象分解为操作系统能够理解的原始数据类型,并在进程之间按次序排列对象。那种排列对象的代码写起来是很乏味的,因此Android通过AIDL来为你处理这些事情。 注意: 只有在你允许来自于不同的应用的客户端访问你的service以实现IPC,并想要在你的service中处理多线程时,才需要使用AIDL。如果你不需要跨不同应用执行并发IPC,你应该通过 实现一个Binder 来创建你的接口,或者如果你想要执行IPC,但不需要处理多线程,可以 使用一个 Messenger 来实现你的接口。无论哪种,请确保在实现一个AIDL之前,你理解了 Bound Services 。/ 在开始设计你的AIDL接口之前,请意识到对于一个AIDL接口的调用是 直接的函数调用 (大概指的是阻塞调用,在调用一个IPC方法时,客户端线程会一直等待,直到service端处理完成并返回) 。你不应该假设调用所发生的线程。依赖于调用是来自于本进程的一个线程,还是一个远端进程,则会发生不同的事情。特别地: 发起于本进程的调用将在发起调用相同的线程中执行

Python process forked by NodeJS - Alternative to process.send() for Python?

試著忘記壹切 提交于 2019-12-09 12:52:05
问题 I'm forking a Python script with NodeJS and when forked, by default, NodeJS create an IPC between this new process and the parent. With NodeJS, to send message from a child to the parent I do process.send({msg : 'toto'}) How can I do that with Python ? http://nodejs.org/api/child_process.html#child_process_child_process_spawn_command_args_options 回答1: Ok I found it, finally is quite easy. It's only about writing on the right file descriptor. On the NodeJS side parameter, spawn your script

How can I communicate between running python code and nodejs

寵の児 提交于 2019-12-09 05:23:20
问题 I'd like to have some python code running and communicating with a nodejs express server. So far, I can get my nodejs server to call python functions via one of two mechanisms, either to spawn a python task or to have it talk to a zerorpc python server. For the first, a la http://www.sohamkamani.com/blog/2015/08/21/python-nodejs-comm/, this works: var express = require( "express" ); var http = require( "http" ); var app = express(); var server = http.createServer( app ).listen( 3000 ); var io

Condition Variable in Shared Memory - is this code POSIX-conformant?

≡放荡痞女 提交于 2019-12-09 00:55:16
问题 Does the POSIX standard allow a named shared memory block to contain a mutex and condition variable? We've been trying to use a mutex and condition variable to synchronise access to named shared memory by two processes on a LynuxWorks LynxOS-SE system (POSIX-conformant). One shared memory block is called "/sync" and contains the mutex and condition variable, the other is "/data" and contains the actual data we are syncing access to. We're seeing failures from pthread_cond_signal() if both

Passing information between two seperate programs

99封情书 提交于 2019-12-08 21:44:47
I want to pass a value of an input variable in my program lets say#1 to another program #2 and i want #2 to print the data it got to screen, both are needed to be written in c++. The this will be on Linux. In response to your comment to Roopesh Majeti's answer, here's a very simple example using environment variables: First program: // p1.cpp - set the variable #include <cstdlib> using namespace std;; int main() { _putenv( "MYVAR=foobar" ); system( "p2.exe" ); } Second program: // p2.cpp - read the variable #include <cstdlib> #include <iostream> using namespace std;; int main() { char * p =

Signalling to a parent process that a child process is fully initialised

浪尽此生 提交于 2019-12-08 21:03:16
问题 I'm launching a child process that exposes a WCF endpoint. How can I signal from the child process to the parent process that the child is fully initialised and that it can now access the endpoint? I'd thought about using Semaphores for this purpose but can't quite figure out how to achieve the required signal. string pipeUri = "net.pipe://localhost/Node0"; ProcessStartInfo startInfo = new ProcessStartInfo("Node.exe", "-uri=" + pipeUri); Process p = Process.Start(startInfo);

cross memory attach. Not able to send the remote address using pipes

依然范特西╮ 提交于 2019-12-08 13:50:41
问题 I had asked my question on cross memory attach (cross memory attach. How do I get the remote address from a child process to a parent process) I am using pipes to transfer the address from child process to parent process. Code: #include <stdio.h> #include <sys/uio.h> #include <sys/types.h> #include <unistd.h> #include <string.h> int main() { int i, nbytes; //nbytes to keep a count of the no. of bytes received int fd[2]; //file descriptor int pid1, ppid; char temp; char string[] = "hello world

zeromq: TypeError: string indices must be integers, not str

落花浮王杯 提交于 2019-12-08 11:25:46
问题 I want to establish publish subscribe communication between to machines. The two machines, that I have, are ryu-primary and ryu-secondary The steps I follow in each of the machines are as follows. In the initializer for ryu-primary (IP address is 192.168.241.131) self.context = zmq.Context() self.sub_socket = self.context.socket(zmq.SUB) self.pub_socket = self.context.socket(zmq.PUB) self.pub_port = 5566 self.sub_port = 5566 def establish_zmq_connection(self): # Socket to talk to server print