---------------------------------subprocess模块详解
https://blog.csdn.net/guogaoan/article/details/37034565
死锁测试代码:
#!/usr/bin/env python
# coding: utf-8
# yc@2013/04/28
import subprocess
def test(size):
print 'start'
cmd = 'dd if=/dev/urandom bs=1 count=%d 2>/dev/null' % size
p = subprocess.Popen(args=cmd, shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, close_fds=True)
#p.communicate() # 推荐使用
p.wait() # 会产生死锁 不推荐
print 'end'
# 64KB
test(64 * 1024)
# 64KB + 1B
test(64 * 1024 + 1)
问题分析:(linux的PIPE管道大小有限制 )
ulimit -a | grep pipe
pipe size (512 bytes, -p) 8
# 一次原子写入为:512Bytes*8=4096Bytes , 4k*16 pipe缓冲大小为:16*4096=65536Bytes 64k
PIPE是操作系统最基本的IPC机制之一。
IPC是什么?
Inter-Process Communication的缩写,含义为进程间通信或者跨进程通信,是指两个进程之间进行数据交换的过程。
在Linux中,是以进程为单位bai分配和管理资源的du。出于保护机制,zhi一个进程不能直接访问另dao一个进程的资源,也就是说,进程之间互相封闭。但是,一个复杂的应用系统中,通常会使用多个相关的进程来共同完成一项任务,因此要求进程之间必须能够互相通信,从而共享资源和信息。所以,操作系统内核必须提供进程间的通信机制(IPC)。
IPC机制种类:采用命名管道(name pipe),消息队列(message queue),信号(signal),内存共享(share memory);
------------------------------------------扩展阅读dd命令:
https://blog.csdn.net/qq_33160790/article/details/77488160
实用例子:
12.测试硬盘的读写速度
#dd if=/dev/zero bs=1024 count=1000000 of=/root/1Gb.file
#dd if=/root/1Gb.file bs=64k | dd of=/dev/null