Chinaunix首页 | 论坛 | 博客
  • 博客访问: 1178210
  • 博文数量: 252
  • 博客积分: 5421
  • 博客等级: 大校
  • 技术积分: 2418
  • 用 户 组: 普通用户
  • 注册时间: 2007-06-17 12:59
文章分类

全部博文(252)

文章存档

2017年(3)

2016年(18)

2015年(31)

2014年(18)

2013年(7)

2012年(8)

2011年(12)

2010年(30)

2009年(32)

2008年(57)

2007年(36)

分类: 系统运维

2014-08-09 22:01:16


  1. #!/usr/bin/python
  2. # -- coding: UTF-8 --
  3. import sys, os;

  4. storecmd = 'php /home/wwwroot/script/store.php -d';
  5. grepcmd = 'ps aux | grep store.php | grep -v grep';


  6. maxProcessNum = 1;
  7. boolkill = False;
  8. if len(sys.argv)>1:
  9.     for i in sys.argv[1:]:
  10.         if i.isdigit():
  11.             maxProcessNum = int(i);
  12.         if i=='-kill':
  13.             boolkill = True;


  14. pids = [];
  15. output = os.popen(grepcmd).readlines();
  16. if len(output)>0:
  17.     for line in output:
  18.         pids.append(int(line.split()[1]));
  19.     print('store.php is running, pid:'+' '.join([str(i) for i in pids]));
  20.     if boolkill:
  21.         for pid in pids: os.kill(pid,9);
  22.         print('has been killed');
  23.         sys.exit();
  24. else:
  25.     if boolkill:
  26.         print('store.php is not running');
  27.         sys.exit();

  28. currProcessNum = len(pids);
  29. newProcessNum = maxProcessNum - currProcessNum;
  30. if newProcessNum==0:
  31.     sys.exit();
  32. elif newProcessNum<0:
  33.     sys.exit();
  34. else:
  35.     print('need to create %d processes' % (newProcessNum));
  36.     for i in range(1,newProcessNum+1):
  37.         exitCode = os.system(storecmd);
  38.         if exitCode==0:
  39.             print('no:%d - start ok' % (currProcessNum+i));
  40.         else:
  41.             print('no:%d - start failed, exitCode:%d' % (currProcessNum+i,exitCode));

阅读(980) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~