#!/usr/bin/python # -*- coding: UTF-8 -*- import platform,os import time import subprocess import sys import ctypes def get_sysinfo(): sys = platform.system() return os.getpid(),sys def get_path(): p=os.path.split(os.path.realpath(__file__)) # ('D:\\workspace\\python\\src\\mysql', 'dao.py') p=os.path.split(p[0]) if not p: os.mkdir(p) return p[0] def get_pid_path(): return get_path() +'/tmp/yqs.pid' def check_pid(pid = 0,osname=''): if pid is None or pid == 0: return False wincmd = 'tasklist /FI "PID eq %s" /FI "IMAGENAME eq python.exe "' % str(pid) lincmd = 'ps ax |grep %s |grep python' % str(pid) cmd,size = (wincmd,150) if osname=='Windows' else (lincmd,20) returnstr=subprocess.Popen(cmd,stdout=subprocess.PIPE,stderr=subprocess.PIPE, shell=True) data = returnstr.stdout.read() return len(data) > size def read_pid(): if os.path.exists(get_pid_path()): try: with open(get_pid_path(),'r') as f: strpid = f.readline().strip() return int(strpid) except Exception : return None return None def rm_pid(): if os.path.exists(get_pid_path()): os.remove(get_pid_path()) def kill(pid): """kill function for Win32""" kernel32 = ctypes.windll.kernel32 handle = kernel32.OpenProcess(1, 0, pid) return (0 != kernel32.TerminateProcess(handle, 0)) def check_run(): pid,osname = get_sysinfo() if not os.path.exists(get_pid_path()): with open(get_pid_path(),'w') as f: f.write(str(pid)) return False ''' 开始检查 ''' rs = check_pid(read_pid(),osname) if not rs : with open(get_pid_path(),'w') as f: f.write(str(pid)) return rs class Control : def start(self): if check_run(): print 'pro has run' else : print 'pro start...' time.sleep(1000) def stop(self): filePid = read_pid() if filePid is not None and filePid > 0: print 'pro has kill %s' % filePid kill(filePid) rm_pid() else : print 'Process has closed' def check(self): filePid = read_pid() if not filePid or not check_run() : message = "Process has closed\n" sys.stderr.write(message) else : message = "The process has been run, the process id:%d\n" sys.stderr.write(message % filePid) def helpInfo(self): print "usage: start|stop|check|help" if __name__ == "__main__": contr=Control() if len(sys.argv) == 2: param = sys.argv[1] if 'start' == param: contr.start() elif 'stop' == param: contr.stop() elif 'check' == param: contr.check() elif 'help' == param: contr.helpInfo() else: print r"not yes cmd" sys.exit(2) else: print "usage: %s start|stop|check|help" % sys.argv[0]
使用方法: python xxx.py start/stop
相关推荐
在python中我们可以使用APScheduler进行定时任务。 APScheduler的具体编码这里就不介绍...二、停止计划任务的Python脚本 如何停止呢,可使用如下方法: 其实在执行命令:python apschedulerscript.py &之后会在控制台
1)启动性能监控脚本,cpu与memory信息记录于文件中。 ./watch_start runtime filePrefix runtime暂时为运行次数。根据runtime计算最佳统计间隔和次数的模块未实现。 记录文件名:filePrefix_timestamp_cpu.txt 或 ...
是我的博客 在Ubuntu下后台持续运行Python程序 的配套代码,包含了启动和停止脚本
1、通过java调用Python命令执行datax任务调度 2、自动开始任务和调度结束关闭任务调度释放内存 3、如果我们在cmd使用命令调度,执行完毕后无法释放内存,会造成内存泄露不足,出现报错“Error occurred during ...
最近日常测试中经常需要手动启动或停止docker,于是决定写一个Shell脚本来代替人工操作,另外该脚本,也可以通过Python脚本实行远程调用,详细如下所示: 目前该脚本是将Container ID写死在脚本中,当然也可以通过...
springboot jar包启动脚本,启动:./lpwa./sh start 停止:./lpwa./sh stop 重启:./lpwa./sh restart
ec2-自动启动-停止 自动启动和停止 AWS EC2 实例的 Cloud Formation 和 python 脚本
一、问题: 今天在部署Python Flask项目到线上的时候,在虚拟环境中,运行项目可以正常访问到api,但是在Xshell中,一旦Ctrl+C或者关闭ssh,他就停止了,api...run.py为Flask项目的启动脚本,在python环境中不间断的运
一个使用 boto 在 Amazon AWS EC2 上自动启动和停止实例的小型 Python 脚本 设置 首先,你需要 Python Boto 已经安装在大多数 Amazon EC2 AMI 中,如果您在其他地方运行它,只需: Debian/Ubuntu sudo apt-get ...
dockerized haproxy 这个docker容器提供了haproxy和一个小的python脚本,当容器启动或停止时,它将通过可用的docker容器重新创建其配置。它是如何工作的haproxy正在侦听端口80,并将所有请求转发到特定的docker-...
定义一个接口以允许将 OpenCog 实验编写为简短的 Python 脚本。 功能 控制本地机器或 Vagrant 机器上的 OpenCog 服务器 控制 Vagrant 机器上的 RelEx 服务器(尚未添加本地机器功能) 启动和停止 OpenCog 服务器 ...
该脚本使用python通过winpcap和网卡驱动交互,从而实现抓包和跨协议栈的发包功能; 在入口函数中增加了脚本使用说明和举例! s = SNIFFER(interface)#设置待监听的网卡 s.start()#设置启动线程开始监听网卡 time....
使用boto3 SDK的AWS的Python脚本 脚本 描述 使用特定标签启动所有实例 使用特定标签停止所有实例 获取EC2公共IP并更改Route53'A'记录 启动EC2,获取公共IP并更改Route53'A'记录 安装 需要Python和 。 git ...
将Chromecast设备收集到房间中,可以通过--standalone选项--standalone设备进行单独处理的旧操作目录 记录中谢谢 安装 使用虚拟环境启动python脚本首先确保您至少安装了python3.6和venv,然后为您的python脚本创建...
当您停止 Python 脚本时,Android 应用程序将关闭 - 就这么简单! Python 脚本需要pyusb 我写这篇文章的目标是让我的 Nexus 4 成为 Raspberry Pi 的传感器。 Raspberry Pi 没有 ADB,Nexus 4 不能轻松使用 USB-...
Python 3.6 在您的工作文件夹(例如您的主文件夹)中 git clone https://github.com/yevgenykuz/checkmarx-jmeter-runner.git 运行此脚本之前-确保所提供的tomcat用户具有“ manager-script”权限(可在“ tomcat-...
12.1 启动与停止线程 12.2 判断线程是否已经启动 12.3 线程间通信 12.4 给关键部分加锁 12.5 防止死锁的加锁机制 12.6 保存线程的状态信息 12.7 创建一个线程池 12.8 简单的并行编程 12.9 Python的全局锁...
python-daemon, 用于 Unix,Linux和 OS X的python daemonizer python-daemonizer类这是一个 python 类,可以守护 python 脚本,以便它可以在后台继续运行。 它在 Unix 。Linux和 OS X 上工作,创建了一个PID文件,并...
脚本收集 ... genymotion.sh->通过命令行启动停止genmotion VM gitrebase->当您必须使用上游更改来更新fork而不在回购中添加额外的提交时。 http->尝试使用多种语言在此位置启动Web服务器作为后备 pub
然后,脚本启动/停止将单个循环流式传输到命名管道的其他 sox 实例。 $ mkfifo loop_0 $ mkfifo loop_1 $ mkfifo loop_2 $ sox --combine mix-power -r 44100 -e signed -b 16 -c 2 loop_0 -r 44100 -e signed -b...