ipc

On localhost, how do I pick a free port number?

∥☆過路亽.° 提交于 2019-12-17 04:38:14
问题 I'm trying to play with inter-process communication and since I could not figure out how to use named pipes under Windows I thought I'll use network sockets. Everything happens locally. The server is able to launch slaves in a separate process and listens on some port. The slaves do their work and submit the result to the master. How do I figure out which port is available? I assume I cannot listen on port 80 or 21? I'm using Python, if that cuts the choices down. Thanks! 回答1: Do not bind to

Example of Named Pipes

南楼画角 提交于 2019-12-16 22:22:11
问题 How do I write a simple--bare minimum needed for it to work--test application that illustrates how to use IPC/Named Pipes? For example, how would one write a console application where Program 1 says "Hello World" to Program 2 and Program 2 receives message and replies "Roger That" to Program 1. 回答1: using System; using System.IO; using System.IO.Pipes; using System.Linq; using System.Text; using System.Threading.Tasks; namespace ConsoleApplication1 { class Program { static void Main(string[]

linux消息队列操作

安稳与你 提交于 2019-12-16 18:26:02
对消息队列的操作无非有以下三种类型: 1、 打开或创建消息队列 消息队列的内核持续性要求每一个消息队列都在系统范围内相应唯一的键值,所以,要获得一个消息队列的描写叙述字,仅仅需提供该消息队列的键值就可以; 注:消息队列描写叙述字是由在系统范围内唯一的键值生成的,而键值能够看作相应系统内的一条路经。 2、 读写操作 消息读写操作很easy,对开发者来说,每一个消息都相似例如以下的 数据 结构: struct msgbuf{ long mtype; char mtext[1]; }; mtype成员代表消息类型,从消息队列中读取消息的一个重要根据就是消息的类型;mtext是消息内容,当然长度不一定为1。因此,对于发送消息来说,首先预置一个msgbuf缓冲区并写入消息类型和内容,调用对应的发送函数就可以;对读取消息来说,首先分配这样一个msgbuf缓冲区,然后把消息读入该缓冲区就可以。 3、 获得或设置消息队列属性: 消息队列的信息基本上都保存在消息队列头中,因此,能够分配一个相似于消息队列头的结构(struct msqid_ds,见 附录 2 ),来返回消息队列的属性;相同能够设置该 数据 结构。 消息队列API 1、文件名称到键值 #include <sys/types.h> #include <sys/ipc.h> key_t ftok (char*pathname, char

System V IPC

北城以北 提交于 2019-12-16 18:21:35
1、概述    System V IPC共有三种类型:System V消息队列、System V 信号量、System V 共享内存区。 System V IPC操作函数如下: 2、key_t键和ftok函数   三种类型的IPC使用key_t值作为他们的名字,头文件<sys/types.h>把key_t定义为一个整数,通常是一个至少32位的整数,由ftok函数赋予的。函数ftok把一个已存的路径和一个整数标识符转换成一个key_t值,称为IPC键。函数原型如下: #include <sys/types.h>#include <sys/ipc.h> key_t ftok(const char *pathname, int proj_id); //成功返回IPC键,出错返回-1 写个程序看看ftok是如何组合IPC键,程序如下: 1 #include <stdio.h> 2 #include <stdlib.h> 3 #include <unistd.h> 4 #include <sys/types.h> 5 #include <sys/ipc.h> 6 #include <sys/stat.h> 7 #include <errno.h> 8 9 typedef unsigned long u_long; 10 11 int main(int argc,char *argv[])

perl 信号量 Semaphore

大兔子大兔子 提交于 2019-12-16 12:40:57
信号量作为锁使用事例。 #!/usr/bin/perl # use strict; use IPC::Semaphore; use IPC::SysV qw(IPC_PRIVATE S_IRUSR S_IWUSR IPC_CREAT IPC_NOWAIT SEM_UNDO); our $sem = IPC::Semaphore->new(IPC_PRIVATE, 1, S_IRUSR | S_IWUSR | IPC_CREAT); $sem->setval(0,1); my $pid = fork(); die "fork failed" unless defined $pid; if ($pid > 0) { $sem->op(0,-1,SEM_UNDO); my $i = 10; while($i > 0){ print "parent process i= $i\n"; $i--; } $sem->op(0,1,SEM_UNDO); } elsif ($pid == 0){ $sem->op(0, -1, SEM_UNDO); my $i = 10; while($i > 0) { print "child process i = $i\n"; $i--; } } $sem->remove() if defined $sem; -> # ./testsem.pl parent

IPC之shm.c源码解读

廉价感情. 提交于 2019-12-16 10:56:59
// SPDX-License-Identifier: GPL-2.0 /* * linux/ipc/shm.c * Copyright (C) 1992, 1993 Krishna Balasubramanian * Many improvements/fixes by Bruno Haible. * Replaced `struct shm_desc' by `struct vm_area_struct', July 1994. * Fixed the shm swap deallocation (shm_unuse()), August 1998 Andrea Arcangeli. * * /proc/sysvipc/shm support (c) 1999 Dragos Acostachioaie <dragos@iname.com> * BIGMEM support, Andrea Arcangeli <andrea@suse.de> * SMP thread shm, Jean-Luc Boyard <jean-luc.boyard@siemens.fr> * HIGHMEM support, Ingo Molnar <mingo@redhat.com> * Make shmmax, shmall, shmmni sysctl'able, Christoph

CocosCreator编辑器扩展2-ipc

拈花ヽ惹草 提交于 2019-12-15 09:35:43
总结来说写编辑器扩展需要知道几部分就可以写一些简单插件了,1需要知道你的包的文件都是干嘛的2.明白进程之间的通信(ipc),3可以自己创建自定义编辑器面板,4,了解调用引擎api和项目脚本,以及管理项目资源,这大致几部分,说到底如果你能熟练运用文档应该都不是问题。 首先根据文档来了解一下ipc:Cocos Creator 的编辑器是基于 GitHub 开发的 Electron 内核。Electron 是一个集成了 Node.js 和 Chromimu 的跨平台开发框架。在 Electron 的架构中,一份应用程序由主进程和渲染进程组成,其主进程负责管理平台相关的调度,如窗口的开启关闭,菜单选项,基础对话框等等。而每一个新开启的窗口就是一个独立的渲染进程。在 Electron 中,每个进程独立享有自己的 JavaScript 内容,彼此之间无法直接访问。当我们需要在进程之间传递数据时,就需要使用进程间通信(IPC)。 总结起来就是说一个包应该是有主进程,也就是main,和渲染进程,也就是panel面板,但是各个进程享有自己的javaScript内容无法通信,所以就有了IPC进程之间的通信来告诉对方需要做什么。比如之前的package.json里 { main-menu": { "Packages/Hello World": { "message": "hello-world:say

11、UC IPC进程间通信

自作多情 提交于 2019-12-15 00:59:04
耦合性 代码的耦合性越低越好 内聚性 内聚性越强越好 一、IPC进程间通讯 system v IPC 使用命令ipcs可以查看system v IPC的对象 第一步:获取一个键值(唯一的值) 如果获取一个键值? 使用ftok(3)获取一个键值 # include <sys/types.h> # include <sys/ipc.h> key_t ftok ( const char * pathname , int proj_id ) ; 功能:转换pathname和proj_id为一个key值 参数: pathname:指定文件的名字 proj_id:一个整数,这个整数的低 8 位不能为 0 返回值: - 1 错误 errno被设置 成功 key值被返回 举例验证,使用ftok(3)获取一个键值 代码参见 ftok.c 如果文件名字和数字完全一样,多次运行进程产生的key值,完全一样。 第二步:通过键值获取一块内存,将这块内存id返回 第三步:通过内存的id操作这块内存 包含以下三个方面: 1、消息队列 通过键值获取一块内存,将这块内存id返回。 需要使用到msgget(2)获取内核内存的id # include <sys/types.h> # include <sys/ipc.h> # include <sys/msg.h> int msgget ( key_t key ,

Java: How can I create an application that will only start if an instance of it doesn't exist and call the instance if it does exist?

☆樱花仙子☆ 提交于 2019-12-14 03:58:07
问题 I am trying to create a program with Java that can only have one instance of it running at a time. I am using Sockets and ServerSockets to try to achieve this. How the program is supposed to work is: The main method will check if any parameters have been passed, it will try to write the first parameter to the server, if it fails that means, that means that this is the only running instance, so it will open the ServerSocket and then start the frame. If it doesn't fail then the application is

shmget for IPC in linux [closed]

喜欢而已 提交于 2019-12-14 03:31:08
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 9 months ago . I'm really new to linux OS. Can someone say how to do this work with linux. I'm not asking the C code. It's hard to understand it. Thank you 1. First program creates a shared memory area using shmget() and maps it to its address space. Then it writes "Hello" in to that shared