socketpair初识
#include <string.h>
#include <unistd.h>
#include <sys/types.h>
#include <error.h>
#include <errno.h>
#include <sys/socket.h>
#include <stdlib.h>
#define BUF_SIZE 300
int main()
{
int s[2];
char *sBuffer = (char *)malloc(BUF_SIZE);
pid_t pid;
char sContent[200];
socketpair(AF_UNIX,SOCK_STREAM,0,s);
pid = fork();
if(pid>0)
{
close(s[1]);
printf("master的使用socket是%d,关掉是是%d\n",s[0],s[1]);
sprintf(sContent,"worker%d!开门!查水表!!!我是master%d",pid,getpid());
write(s[0],sContent,strlen(sContent));
sleep(1);
read(s[0], sBuffer , BUF_SIZE );
printf("master%d听到:%s\n",getpid(),sBuffer);
}
else
{
close(s[0]);
printf("worker的使用socket是%d,关掉是是%d\n",s[1],s[0]);
read(s[1], sBuffer , BUF_SIZE );
printf("worker%d听到:%s\n",getpid(),sBuffer);
sprintf(sContent,"master%d!我家水表在外面!!!我是worker%d",getppid(),getpid());
write(s[1],sContent,strlen(sContent));
}
return 0;
}
socketpair初识的更多相关文章
- Android动画效果之初识Property Animation(属性动画)
前言: 前面两篇介绍了Android的Tween Animation(补间动画) Android动画效果之Tween Animation(补间动画).Frame Animation(逐帧动画)Andr ...
- 初识Hadoop
第一部分: 初识Hadoop 一. 谁说大象不能跳舞 业务数据越来越多,用关系型数据库来存储和处理数据越来越感觉吃力,一个查询或者一个导出,要执行很长 ...
- python学习笔记(基础四:模块初识、pyc和PyCodeObject是什么)
一.模块初识(一) 模块,也叫库.库有标准库第三方库. 注意事项:文件名不能和导入的模块名相同 1. sys模块 import sys print(sys.path) #打印环境变量 print(sy ...
- 初识IOS,Label控件的应用。
初识IOS,Label控件的应用. // // ViewController.m // Gua.test // // Created by 郭美男 on 16/5/31. // Copyright © ...
- UI篇(初识君面)
我们的APP要想吸引用户,就要把UI(脸蛋)搞漂亮一点.毕竟好的外貌是增进人际关系的第一步,我们程序员看到一个APP时,第一眼就是看这个软件的功能,不去关心界面是否漂亮,看到好的程序会说"我 ...
- Python导出Excel为Lua/Json/Xml实例教程(一):初识Python
Python导出Excel为Lua/Json/Xml实例教程(一):初识Python 相关链接: Python导出Excel为Lua/Json/Xml实例教程(一):初识Python Python导出 ...
- 初识SpringMvc
初识SpringMvc springMvc简介:SpringMVC也叫Spring Web mvc,属于表现层的框架.Spring MVC是Spring框架的一部分,是在Spring3.0后发布的 s ...
- 初识redis数据类型
初识redis数据类型 1.String(字符串) string是redis最基本的类型,一个key对应一个value. string类型是二进制安全的.意思是redis的string可以包含任何数据 ...
- Redis初识、设计思想与一些学习资源推荐
一.Redis简介 1.什么是Redis Redis 是一个开源的使用ANSI C 语言编写.支持网络.可基于内存亦可持久化的日志型.Key-Value 数据库,并提供多种语言的API.从2010 年 ...
随机推荐
- leetcode551
public class Solution { public bool CheckRecord(string s) { ; ; ; var preChar = '\0'; ; i < s.Len ...
- 11.使用ForwardAction实现页面屏蔽。
转自:https://wenku.baidu.com/view/84fa86ae360cba1aa911da02.html 我们在jsp页面之间写链接总会是.../xxx.jsp,而如果我们想屏蔽掉具 ...
- 基于OpenGL编写一个简易的2D渲染框架-11 重构渲染器-Renderer
假如要渲染一个纯色矩形在窗口上,应该怎么做? 先确定顶点的格式,一个顶点应该包含位置信息 vec3 以及颜色信息 vec4,所以顶点的结构体定义可以这样: struct Vertex { Vec3 p ...
- 获取request错误信息
from: https://stackoverflow.com/questions/19370436/get-errno-from-python-requests-connectionerror 当使 ...
- SWFUpload乱码问题的解决
目前比较流行的是使用SWFUpload控件,这个控件的详细介绍可以参见官网http://demo.swfupload.org/v220/index.htm 在使用这个控件批量上传文件时发现中文文件名都 ...
- ArcGIS 复制要素
DataManagementTools.General.Copy DataManagementTools.Features.CopyFeatures ConversionTools.ToGeodata ...
- SQL Server 2008用'sa'登录失败,启用'sa'登录的办法
首先”为什么用sa登录不了,提示登录失败呢?" 当然,自己装SQL Server 2008的时候根本就没有用sa登录的方法,装数据库的时候是用windows身份登录的. 如果要启用用户名为“ ...
- jquery parents用法
之前一直用find 现在用parents var w = $("div"); w = $("div").parents('.class'); //在Parent ...
- General error 2006 MySQL server has gone away
写入配置文件的办法: max_allowed_packet = 16M //但是这种有时候不支持,1024*1024*16这种有的也不支持 max_allowed_packet = 16777216 ...
- 真验货客户尾缀sql
'; --select * from TB_ADDBOMWG_LOG; --SELECT * FROM TB_MAN_ROUTING_QM; SELECT * FROM IN_ITEM WHERE I ...