ps aux | grep chrome

杀死进程最安全的方法是单纯使用kill命令,不加修饰符,不带标志。

首先使用ps -ef命令确定要杀死进程的PID,然后输入以下命令:

# kill -pid

注释:标准的kill命令通常都能达到目的。终止有问题的进程,并把进程的资源释放给系统。然而,如果进程启动了子进程,只杀死父进程,子进程仍在运行,因此仍消耗资源。为了防止这些所谓的僵尸进程,应确保在杀死父进程之前,先杀死其所有的子进程。

*确定要杀死进程的PIDPPID 

# ps -ef | grep httpd

*以优雅的方式结束进程

# kill -l PID

-l选项告诉kill命令用好像启动进程的用户已注销的方式结束进程。当使用该选项时,kill命令也试图杀死所留下的子进程。但这个命令也不是总能成功--或许仍然需要先手工杀死子进程,然后再杀死父进程。

*TERM信号

给父进程发送一个TERM信号,试图杀死它和它的子进程。

# kill -TERM PPID

*killall命令

killall命令杀死同一进程组内的所有进程。其允许指定要终止的进程的名称,而非PID

# killall httpd

*停止和重启进程

有时候只想简单的停止和重启进程。如下:

# kill -HUP PID

该命令让Linux和缓的执行进程关闭,然后立即重启。在配置应用程序的时候,这个命令很方便,在对配置文件修改后需要重启进程时就可以执行此命令。

*绝杀 kill -9 PID

同意的 kill -s SIGKILL

这个强大和危险的命令迫使进程在运行时突然终止,进程在结束后不能自我清理。危害是导致系统资源无法正常释放,一般不推荐使用,除非其他办法都无效。

当使用此命令时,一定要通过ps -ef确认没有剩下任何僵尸进程。只能通过终止父进程来消除僵尸进程。如果僵尸进程被init收养,问题就比较严重了。杀死init进程意味着关闭系统。

如果系统中有僵尸进程,并且其父进程是init,而且僵尸进程占用了大量的系统资源,那么就需要在某个时候重启机器以清除进程表了。

import os import time import platform from selenium import webdriver as webdriver1 from selenium.webdriver.ie.options import Options from selenium.webdriver.support import expected_conditions as EC from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.common.by import By from config import global_wait,root_url,use_edge,iedriver_path,edgedriver_path,chromedriver_path from public.basiclogger import LOGGING class BaseCase(object): '''基础用例''' def get_web_driver(self,url,data=None,browser='ie'): if browser=='chrome': #if platform.system()=="Windows": # os.system(r'taskkill /f /im chrome.exe') #else: # os.system(r"ps aux |grep chrome|awk '{print $2}'|xargs -i kill {}") options = webdriver1.ChromeOptions() options.add_experimental_option('excludeSwitches', ['enable-logging']) self.driver = webdriver1.Chrome(executable_path=chromedriver_path,options=options) self.driver.get(url) self.driver.maximize_window() self.driver.implicitly_wait(global_wait) else: #启动IE之前先杀死电脑上所有的IE if use_edge: os.system(r'taskkill /f /im msedge.exe') else: os.system(r'taskkill /f /im iexplore.exe') if use_edge: file1=edgedriver_path else: file1=iedriver_path options = Options() options.ignore_protected_mode_settings = True options.ignore_zoom_level = True if use_edge: options.attach_to_edge_chrome = True options.edge_executable_path = r"C:\Program Files (x86)\Microsoft\Edge\Application\msedge.exe" else: options.add_argument('--user-agent="Mozilla/5.0 (Windows NT 10.0; WOW64; Trident/7.0; rv:11.0) like Gecko"') self.driver=webdriver1.Ie(executable_path=file1,options=options) self.driver.get(url) self.driver.maximize_window() self.driver.implicitly_wait(global_wait) def get_logger(self): #创建日志文件名 filename=self.data["case_name"]+'_'+time.strftime("%Y-%m-%d_%H-%M-%S") #保存连接 filename1=os.path.join(r'test_log',filename+r'.log') LOGGING1=LOGGING(log_name=filename,log_dir="test_log") self.logger=LOGGING1.logObject self.LOGGER=LOGGING1
05-30
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值