我还没有管理我的应用程序上的所有错误.所以我想知道是否有可能在崩溃时杀死整个应用程序?
(当出现"app MyApp crash,force close"消息时,我希望当用户点击"强制关闭"时应用程序被杀死)
当我输入命令ps -ef | grep sharatds时,我得到一个进程列表.
sharatds 13164 13163 0 20:53 pts/2 00:00:00 [bt.C.256] <defunct>
sharatds 13165 13163 0 20:53 pts/2 00:00:00 [rsh] <defunct>
sharatds 13199 13163 0 20:53 pts/2 00:00:00 [rsh] <defunct>
sharatds 13233 13163 0 20:53 pts/2 00:00:00 [rsh] <defunct>
sharatds 13267 13163 0 20:53 pts/2 00:00:00 [rsh] <defunct>
sharatds 13301 13163 0 20:53 pts/2 00:00:00 [rsh] <defunct>
sharatds 13335 13163 0 20:53 pts/2 00:00:00 [rsh] <defunct>
sharatds 13369 13163 0 20:53 pts/2 00:00:00 [rsh] <defunct>
sharatds 13403 13163 …Run Code Online (Sandbox Code Playgroud) 我已经实现了一种方法来查找进程(“iexplore.exe”)是否正在运行,我现在需要找到一种方法来从 Inno Setup 中关闭它(终止进程)。
strProg := 'iexplore.exe';
winHwnd := FindWindowByWindowName(strProg);
MsgBox('winHwnd: ' + inttostr(winHwnd), mbInformation, MB_OK );
if winHwnd <> 0 then
retVal:=postmessage(winHwnd,WM_CLOSE,0,0);
Run Code Online (Sandbox Code Playgroud)
上面示例中的消息框将始终返回 0,因此永远不会获得句柄。(WM_CLOSE示例中的常量已正确初始化)我需要另一种方法来做到这一点,希望这种方法不涉及编写执行此操作的 C++ DLL(我不精通 C++,我可能能够在 C# 中编写一个 DLL ,但我不知道 Inno Setup 是否会与之互操作)。
这个 C# DLL 将获取进程列表,遍历进程的名称,找到匹配项(==“iexplorer”),然后终止具有该名称的进程......但是我仍然希望找到一个更简单的解决方案,以便我不必与 Pascal 脚本互操作。
提前致谢!
我有这个代码可以正确地杀死任何正在运行的Excel进程.
public static void killExcel(){
while (isProcessRuning("EXCEL.EXE")){
Runtime.getRuntime().exec("taskkill /IM EXCEL.EXE");
}
}
public static boolean isProcessRuning(String serviceName) throws Exception {
Process p = Runtime.getRuntime().exec(TASKLIST);
BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line;
while ((line = reader.readLine()) != null) {
if (line.contains(serviceName)) {
return true;
}
}
return false;
}
Run Code Online (Sandbox Code Playgroud)
我的问题是,如果Excel文件提示保存问题,我有一个无限循环.
我想允许普通用户杀死由 root 用户启动的某个应用程序。
在视觉上:
我添加了这样的一行:
normal_user ALL=(ALL) NOPASSWD: /usr/bin/kill $(ps aux | grep 'target_application' | awk '{print $2}')
Run Code Online (Sandbox Code Playgroud)
但是在保存并以normal_user身份执行以下命令后,我仍然收到输入root密码的提示:
sudo /usr/bin/kill $(ps aux | grep 'target_application' | awk '{print $2}')
Run Code Online (Sandbox Code Playgroud)
那我该怎么办?非常感谢!
我socket.error: No socket could be created在运行web.py脚本时得到一个" ".
有没有办法在OSX Mavericks上的终端中使用单行杀死在端口8080(或我希望的任何其他端口)上运行的所有进程?
我想使用 shell 脚本来建立以太网连接。
我正在使用一个实现为的函数:
function connec()
{
ip link set eth0 up
sleep 5
udhcpc -i eth0
pid=$$
echo $pid
ps
kill -9 $pid
}
Run Code Online (Sandbox Code Playgroud)
但是,脚本返回:
743
743 root 2704 S {script.sh} /bin/bash ./script.sh connect
767 root 2200 S udhcpc -i eth0
Killed
Run Code Online (Sandbox Code Playgroud)
我在商店 767 而不是 743 中没有成功。我也尝试使用 $! 但在这种特定情况下,“echo $pid”返回 0。
我正在尝试使用 MoviePy 从大量图像制作视频。该方法适用于少量图像,但对于大量图像,该过程被终止。添加了大约 500 个图像后,Python 进程使用了大约一半的可用易失性内存。还有更多的图像。
我应该如何解决这个问题?我希望处理完成,我不介意处理时间是否长一点,但如果我能以某种方式限制内存和 CPU 使用情况会很好。使用当前方法,机器在处理时几乎无法使用。
代码如下:
import os
import time
from moviepy.editor import *
def ls_files(
path = "."
):
return([fileName for fileName in os.listdir(path) if os.path.isfile(
os.path.join(path, fileName)
)])
def main():
listOfFiles = ls_files()
listOfTileImageFiles = [fileName for fileName in listOfFiles \
if "_tile.png" in fileName
]
numberOfTiledImages = len(listOfTileImageFiles)
# Create a video clip for each image.
print("create video")
videoClips = []
imageDurations = []
for imageNumber in range(0, numberOfTiledImages):
imageFileName = str(imageNumber) + …Run Code Online (Sandbox Code Playgroud) 我知道我们可以在VBS,PowerShell等中执行此操作.但是,我们不希望使用除了好的批处理脚本之外的其他语言来执行此操作.
已经想出以下几点:
TASKKILL /F /IM "tomcat*"
Run Code Online (Sandbox Code Playgroud)
这将强制终止/停止任何Tomcat的持久实例.此外,这将涵盖Tomcat6.exe,Tomcat6_1.exe,tomcat7.exe等.
我的问题是什么..我们知道我们可以做一个NET START Tomcat6,例如..是否可以:
NET START Tomcat*
Run Code Online (Sandbox Code Playgroud)
?是的,我完全知道如果你在服务器上有多个Tomcat实例,这会失败,因为你必须遍历实例列表.但是,我这样做的原因是因为,我有每月脚本我们必须运行,我试图使批处理脚本更具可移植性.
谢谢.
我不明白什么时候需要杀死子进程。
for package in server.packages:
n = subprocess.Popen(['which', package], stdout=subprocess.DEVNULL)
n.wait()
if n.returncode != 0:
n.kill()
<some other code>
Run Code Online (Sandbox Code Playgroud)
我收到错误(使用 Python3):
ProcessLookupError: [Errno 3] No such process
Run Code Online (Sandbox Code Playgroud)
任何人都可以解释我什么时候子进程自杀以及什么时候需要手动完成?
kill ×10
bash ×2
python ×2
android ×1
awk ×1
batch-file ×1
crash ×1
excel ×1
inno-setup ×1
installation ×1
java ×1
linux ×1
memory ×1
moviepy ×1
port ×1
process ×1
python-3.3 ×1
python-3.4 ×1
subprocess ×1
terminal ×1
tomcat ×1
variables ×1