You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
18 lines
786 B
18 lines
786 B
|
6 days ago
|
# -*- coding: utf-8 -*-
|
||
|
|
"""票 04:带超时杀 java 进程(subprocess timeout 防挂起)。"""
|
||
|
|
import io, sys, subprocess, time
|
||
|
|
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8')
|
||
|
|
|
||
|
|
try:
|
||
|
|
r = subprocess.run(['taskkill', '/F', '/T', '/PID', '34400'],
|
||
|
|
capture_output=True, text=True, timeout=15)
|
||
|
|
print('rc=', r.returncode, '|', (r.stdout or r.stderr).strip()[:200])
|
||
|
|
except subprocess.TimeoutExpired:
|
||
|
|
print('taskkill TIMEOUT (15s) —— 请手动杀 PID 34400')
|
||
|
|
sys.exit(2)
|
||
|
|
|
||
|
|
time.sleep(2)
|
||
|
|
r2 = subprocess.run(['netstat', '-ano'], capture_output=True, text=True, timeout=10)
|
||
|
|
listeners = [l.strip() for l in r2.stdout.splitlines() if 'LISTENING' in l and ':8080' in l]
|
||
|
|
print('[8080 after]', listeners if listeners else 'PORT-FREE')
|