ipc

UNIX/Linux IPC : Reading from a pipe. How to know length of data at runtime?

☆樱花仙子☆ 提交于 2019-12-06 06:16:04
问题 I have a child process which generates some output of variable length and then sends it to the parent using a half duplex pipe. In the parent, how do I use the read() function? Since the data can be of different length each time, how can I at run time know the size of the data to do any malloc() for a buffer? Can the fstat() function be used on a pipe file descriptor? I know that the read() function will read a specified number of bytes but will return 0 if the end of file (not the EOF

perl run background job and force job to finish?

对着背影说爱祢 提交于 2019-12-06 06:12:47
I've got a Perl script that starts a background job to print some logging information into a file, executes something, and then finishes. I would like to end the background process when the script is done, but as far as I know, if I use a double fork as below, then waitpid($pid,0) will wait for the background process to finish, instead of killing it, and kill(9,$pid) won't get rid of the background process. Example script: #!/usr/bin/perl use strict; # Do a first general top my $ret = `top -b -n 1 > logfile`; # Do a background $USER top every minute my $cmd = "top -b -d 60 -n 300 -u $ENV{USER}

How to read from stdin in Matlab

不想你离开。 提交于 2019-12-06 05:48:26
问题 I have a long-running Matlab script for data processing. I want to send it a flag over stdin to tell it I have new data to process. I also want to read a flag from stdout when it is done processing. In other words, I have a Process A that sends a flag about once a minute to Matlab. I want Matlab to wait until it receives this flag. Writing to stdout in a matlab process is as easy as calling fprintf . But how can I read from stdin? Documentation on fopen doesn't mention an input pipe, and

Python/POpen/gpg: Supply passphrase and encryption text both through stdin or file descriptor

烈酒焚心 提交于 2019-12-06 05:20:54
问题 I'm trying to remote control gpg through a python program via POpen . I have a file that contains encrypted data which I want to decrypt, modify and write back to disk re-encrypted. Currently I am storing the decrypted information in a temporary file (which I shred when the program ends). Then I perform my modifications to that file and then re-encrypt it using a function, which pipes the passphrase through stdin . The code for this is as follows: def encrypt(source, dest, passphrase, cipher

Communicate with a WallpaperService

江枫思渺然 提交于 2019-12-06 05:14:06
Is there any way to directly communicate with a WallpaperService from an Activity ? It doesn't look like I can use the normal service communication classes because the onBind method is declared final in the WallpaperService class I'm extending. Worth noting that I'm referring to my WallpaperService not any . Any workarounds if this isn't possible? My solution was to use local sockets. I created an instance of a LocalServerSocket in the constructor of my wallpaper's Engine . Here's a quick implementation. Server runs on a separate thread and is directly tied to the lifecycle of MyEngine . The

is DBus what I'm looking for?

浪尽此生 提交于 2019-12-06 04:48:45
问题 I need an IPC system on Linux. My requirements are: packet/message oriented ability to handle both point-to-point and one-to-many communication no hierarchy, there's no server and client if one endpoint crashes, the others must be notified good support from existing Linux distros existence of a "bind" for Apache, for the purpose of creating dynamic pages sorted in order of importance (roughly). I don't need extreme performance, nor I will be sending high volume of data. I stumbled upon DBus,

How to optimize multithreaded program for use in LSF?

ⅰ亾dé卋堺 提交于 2019-12-06 04:17:44
I am working on a multithreaded number crunching app, let's call it myprogram . I plan to run myprogram on IBM's LSF grid. LSF allows a job to scheduled on CPUs from different machines. For example, bsub -n 3 ... myprogram ... can allocate two CPUs from node1 and one CPU from node2. I know that I can ask LSF to allocate all 3 cores in the same node, but I am interested in the case where my job is scheduled onto different nodes. How does LSF manage this? Will myprogram be run in two different processes in node1 and node2? Does LSF automatically manage data transfer between node1 and node2?

进程间通信 IPC interprocess communication

做~自己de王妃 提交于 2019-12-06 03:47:21
1,管道,FIFO 2, 信号 3,消息队列 4,共享类存 5.文件映射 6.socket ( 1 )管道(Pipe):管道可用于具有亲缘关系进程间的通信,允许一个进程和另一个与它有共同祖先的进程之间进行通信。   ( 2 )命名管道(named pipe):命名管道克服了管道没有名字的限制,因此,除具有管道所具有的功能外,它还允许无亲缘关系进程间的通信。命名管道在文件系统中有对应的文件名。命名管道通过命令mkfifo或系统调用mkfifo来创建。   ( 3 )信号(Signal):信号是比较复杂的通信方式,用于通知接受进程有某种事件发生,除了用于进程间通信外,进程还可以发送信号给进程本身;linux除了支持Unix早期信号语义函数sigal外,还支持语义符合Posix.1标准的信号函数sigaction(实际上,该函数是基于BSD的,BSD为了实现可靠信号机制,又能够统一对外接口,用sigaction函数重新实现了signal函数)。   ( 4 )消息(Message)队列:消息队列是消息的链接表,包括Posix消息队列system V消息队列。有足够权限的进程可以向队列中添加消息,被赋予读权限的进程则可以读走队列中的消息。消息队列克服了信号承载信息量少,管道只能承载无格式字节流以及缓冲区大小受限等缺   ( 5 )共享内存:使得多个进程可以访问同一块内存空间

Passing an object from one application to another in android

泄露秘密 提交于 2019-12-06 03:11:33
After lot of googeling, I could not find any way to pass a object from one application to other application.Though I know that we can pass object from one activty to other activity using Parcel but how to do this between applications? My object is this public class MyObject { private String name; public String getName() { return this.name; } public void setName(String name) { this.name=name; } } Then how to do this like we do for passing object between activities intent.putExtra("key",new MyOject()); I'm assuming you're in charge of both applications. Which of these situations is true? Both

Can Messenger (lightweight alternative to AIDL) be used for cross-application communication?

假装没事ソ 提交于 2019-12-06 02:05:10
问题 A quick question: the Android docs say very clearly that Messenger is an alternative for AIDL for IPC (inter process communication). They never explicitly say though if this extends to processes running in different applications, or just within one app. I strongly suspect the former, but wanted to check. Thanks! Jan 回答1: AIDL is only really used for inter-app IPC. While it is possible to use AIDL for internal communication, it doesn't buy you anything and puts limitations on your Binder