1. 进程的创建 Linux下有四类创建子进程的函数:system(),fork(),exec*(),popen() 1.1. system函数 原型: #include int system(const char *string); system函数通过调用shell程序/bin/sh –c来执行...
分类:
系统相关 时间:
2015-04-09 23:20:06
阅读次数:
312
代码:#!/usr/bin/envpython
#__*__coding:utf8__*__
importSocketServer
importos
classMyServer(SocketServer.BaseRequestHandler):
logname="/opt/nginx/logs/www.xxx.com_access.log"
defhandle(self):
self.pv=os.popen("awk‘{print$1}‘%s|wc-l"%self.logname).read()
se..
分类:
Web程序 时间:
2015-04-08 19:58:20
阅读次数:
165
1.os.popen运行shell列表命令def traverseDirByShell(path):
for f in os.popen('ls ' + path):
print f.strip()2.利用glob模块glob.glob(path)返回带目录的文件名.通配符和shell相似.path不能包含shell变量.def traverseDirByGlob(path)...
分类:
编程语言 时间:
2015-04-05 12:00:28
阅读次数:
192
动态格式化字符串a=[[1,2,3],[4,5,6],[7,8],[10,11,12,13,14]]
foriina:
fmt=‘%s‘*len(i)
argvs=‘‘.join(["i[%s],"%jforjinrange(len(i)])
printfmt%eval(argvs)获取当前登录用户user=subprocess.Popen(‘who‘,shell=True,stdout=subprocess.PIPE)
printlist(set(user.stdout.r..
分类:
编程语言 时间:
2015-03-16 19:44:58
阅读次数:
133
进程间通信方式
传递数据的方式
1.pipe
必须是有亲缘关系的进程之间使用,平时用"ls | grep abc"等命令时用得就是这个,这个"|"我猜测是用了两种系统调用实现,一个是pipe(popen),一个是dup2,没有看过bash或sh的源码,只是猜测。
2.fifo
会在文件...
分类:
编程语言 时间:
2015-03-15 09:31:35
阅读次数:
265
在GNU Linux C编程中,要想进行系统命令的执行的话,只提供了system接口,但是此接口并不能得到命令执行后所输出的值,而只能够得到命令是否执行成功的结果。仅仅这样的功能还是不够的,有的时候是要必须通过命令的输出来判断下一步的结果或步骤的,那么怎么样能够得到system命令执行的结果呢?那就可以使用到popen函数和fgets函数进行命令的输出信息的获取了,实际例子如下:
注意:此接口只...
分类:
其他好文 时间:
2015-03-13 22:27:15
阅读次数:
212
#!/usr/bin#coding:utf-8import os, re, errnols = os.popen('ls *.log').readlines()dirs = []lines = []for line in ls: if line.strip(): dirs.append(re....
分类:
Web程序 时间:
2015-03-10 15:27:20
阅读次数:
281
现在开发的项目是从solaris到linux的应用移植。经常用到popen函数,使用8192字节的数组读取popen输出,但没有进行溢出判断。
刚开始认为是一个简单的内存越界,但对popen和PIPE调查以后,疑惑越来越多了。
1)问题的引出
popen使用管道来记录被调用命令的输出,那么popen的最大写入字节数必然是管道的最大值。
使用linux的ulimit -a来查看系统限制:...
分类:
系统相关 时间:
2015-03-08 18:51:38
阅读次数:
1285
守护进程代码: 1 import time, os 2 import subprocess 3 4 5 def run(): 6 while True: 7 taskList = os.popen('tasklist').read() 8 for path...
分类:
编程语言 时间:
2015-03-04 18:47:13
阅读次数:
167
system()这个函数就不说了,不能读取返回值。#includeint main(){ FILE *fp; char buffer[1024]={0}; fp=popen("ssh root@192.168.1.93 \'ls /\'","r"); ...
分类:
编程语言 时间:
2015-02-27 15:04:14
阅读次数:
180