python语言copy的使用,服务进程ID的获取和停止进程

# -*- coding: utf-8 -*-
import shutil
import os

file = 'D:\\Program Files (x86)\\Jenkins\\workspace\\maven_server\\coe-server\\target\\coe-server-0.0.1-SNAPSHOT.jar'
path = 'D:\\COE\\coe-service\\coe-server\\'

shutil.copy(file,path)

print('---------copy jar包 to coe-server  ----')

#关闭coe-server
print ("获取coe-server的进程ID")
ip_path = 'D:\\COE\\coe-service\\coe-server\\ip.txt'  #wmic process获取processid后,将返回结果存放到txt
os.system('wmic process where commandline="java  -server -Xms1024m -Xmx20480m -jar coe-server-0.0.1-SNAPSHOT.jar" get processid /value  > D:\\COE\\coe-service\\coe-server\\ip.txt')

#获取的txt格式不是utf-8,需要转换type
os.system('type D:\\COE\\coe-service\\coe-server\\ip.txt>D:\\COE\\coe-service\\coe-server\\ip2.txt')

#从txt中分割字符串,获取id值
with open('D:\\COE\\coe-service\\coe-server\\ip2.txt') as file_obj:
    content = file_obj.read()
    print(content.rstrip())
    content = content.rstrip()
    if content != None:
        try:
            id = content.split('=')[1]
            print('id:'+id)
            print ('taskkill /IM '+id+' /F')
            os.system('taskkill /IM '+id+' /F')
            print ('coe-server进程已关闭')
        except Exception as e:
            print ('coe-server进程已关闭',e)
    else:
        print ('coe-server进程已关闭')

 

 

 

---------------------------------

启服务命令:

java -jar coe-server-0.0.1-SNAPSHOT.jar
start /b java -server -Xms1024m -Xmx20480m -jar coe-server-0.0.1-SNAPSHOT.jar

windows查看java进程
wmic process   查看所有
wmic process get name,processid,caption,parentprocessid,threadcount/value 
wmic process where caption="java.exe" get processid,caption,commandline /value
wmic process where commandline="java  -server -Xms1024m -Xmx20480m -jar coe-server-0.0.1-
SNAPSHOT.jar" get name,processid,caption,commandline /value

wmic process where commandline="java  -server -Xms1024m -Xmx20480m -jar coe-server-0.0.1-
SNAPSHOT.jar" get processid /value  > D:\\COE\\coe-service\\coe-server\\ip.txt  将输入内容存放到txt

使用 进程名关闭
taskkill /im mspaint.exe /f

使用 进程id 关闭
taskkill /im 12555 /f

很抱歉,Python并不是操作系统,也不是用于操作系统开发的编程语言,因此Python本身并没有实现银行家算法。但是,我们可以使用Python编写模拟银行家算法的程序来进行资源分配和进程调度的模拟。 以下是一个简单的Python程序,用于模拟银行家算法的资源分配和进程调度: ```python 定义银行家算法的数据结构 class Banker: def __init__(self, available, max_need, allocation): self.available = available # 可用资源 self.max_need = max_need # 进程最大需求量 self.allocation = allocation # 进程已分配资源量 self.need = max_need - allocation # 进程尚需资源量 # 检查是否存在安全序列 def is_safe(self): work = self.available.copy() finish = [False] * len(self.max_need) safe_sequence = [] while True: found = False for i in range(len(self.max_need)): if not finish[i] and all(need <= work for need, work in zip(self.need[i], work)): work = [work[j] + self.allocation[i][j] for j in range(len(work))] finish[i] = True safe_sequence.append(i) found = True if not found: break return all(finish), safe_sequence # 分配资源 def allocate(self, process_id, request): if all(request <= self.need[process_id]) and all(request <= self.available): self.available -= request self.allocation[process_id] += request self.need[process_id] -= request return True else: return False # 释放资源 def release(self, process_id, release): self.available += release self.allocation[process_id] -= release self.need[process_id] += release # 测试程序 if __name__ == '__main__': # 初始化银行家算法的数据结构 available = [3, 3, 2] max_need = [[7, 5, 3], [3, 2, 2], [9, 0, 2], [2, 2, 2], [4, 3, 3]] allocation = [[0, 1, 0], [2, 0, 0], [3, 0, 2], [2, 1, 1], [0, 0, 2]] banker = Banker(available, max_need, allocation) # 模拟进程请求资源 process_id = 0 request = [0, 2, 0] if banker.allocate(process_id, request): print('分配成功') if banker.is_safe()[0]: print('存在安全序列') else: print('不存在安全序列,分配失败') banker.release(process_id, request) else: print('分配失败') ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值