kill

Kill or terminate subprocess when timeout?

强颜欢笑 提交于 2019-11-27 06:55:57
I would like to repeatedly execute a subprocess as fast as possible. However, sometimes the process will take too long, so I want to kill it. I use signal.signal(...) like below: ppid=pipeexe.pid signal.signal(signal.SIGALRM, stop_handler) signal.alarm(1) ..... def stop_handler(signal, frame): print 'Stop test'+testdir+'for time out' if(pipeexe.poll()==None and hasattr(signal, "SIGKILL")): os.kill(ppid, signal.SIGKILL) return False but sometime this code will try to stop the next round from executing. Stop test/home/lu/workspace/152/treefit/test2for time out /bin/sh: /home/lu/workspace/153

android task kill

浪子不回头ぞ 提交于 2019-11-27 06:49:20
问题 I want to kill all tasks that run in android like task killer... What I have done until now is: ActivityManager manager = (ActivityManager) this.getSystemService(ACTIVITY_SERVICE); List<RunningAppProcessInfo> activityes = ((ActivityManager) manager).getRunningAppProcesses(); for (int i = 0; i < activityes.size(); i++){ Log.e("APP: "+i, activityes.get(0).processName); if (!activityes.get(0).processName.equals("app.android.myapp")){ Process.killProcess(activityes.get(0).pid); } } The problem

In perl, killing child and its children when child was created using open

这一生的挚爱 提交于 2019-11-27 06:13:47
问题 Here's my code, with error handling and other stuff removed for clarity: sub launch_and_monitor { my ($script, $timeout) = @_; sub REAPER { while ((my $child = waitpid(-1, &WNOHANG)) > 0) {} $SIG{CHLD} = \&REAPER; } $SIG{CHLD} = \&REAPER; my $pid = fork; if (defined $pid) { if ($pid == 0) { # in child monitor($timeout); } else { launch($script); } } } The launch sub executes a shell script which in turn launches other processes, like so: sub launch($) { my ($script) = @_; my $pid = open(PIPE,

What does `kill -0 $pid` in a shell script do?

微笑、不失礼 提交于 2019-11-27 06:09:15
Basically, what signal does '0' represent, because here I see SIGNAL numbers starting from 1. dwalter sending the signal 0 to a given PID just checks if any process with the given PID is running and you have the permission to send a signal to it. For more information see the following manpages: kill(1) $ man 1 kill ... If sig is 0, then no signal is sent, but error checking is still performed. ... kill(2) $ man 2 kill ... If sig is 0, then no signal is sent, but error checking is still performed; this can be used to check for the existence of a process ID or process group ID. ... This is a

How to kill all processes matching a name?

女生的网名这么多〃 提交于 2019-11-27 05:45:46
Say I want to kill every process containing the word amarok. I can print out the commands I want to execute. But how do I actually make the shell execute them. ie. ps aux | grep -ie amarok | awk '{print "kill -9 " $2}' Output: kill -9 3052 kill -9 3071 kill -9 3076 kill -9 3077 kill -9 3079 kill -9 3080 kill -9 3082 kill -9 3083 kill -9 3084 kill -9 3085 kill -9 3086 kill -9 3087 kill -9 3088 kill -9 3089 kill -9 4031 From man 1 pkill -f The pattern is normally only matched against the process name. When -f is set, the full command line is used. Which means, for example, if we see these lines

Java tool/method to force-kill a child process

与世无争的帅哥 提交于 2019-11-27 05:03:22
I am looking for a Java tool/package/library that will allow me to force-kill a child process. This tool/package/library must work on Windows platform (mandatory). Support for Linux/Unix is desired. My Problem My Java code creates a child process that will simply not react to the standard Java way for killing a child process: process.destroy(), and, since I do not have the child's source code, I cannot program it to better handle termination requests. I have tried closing the child process' error input and output stream before calling destroy(), and for no effect. I have even tried passing

How do I kill an Activity when the Back button is pressed?

别等时光非礼了梦想. 提交于 2019-11-27 04:03:12
I got an Activity that when it starts, it loads an image from the internet. In an effort to save memory, when the Activity is left by the back button being pressed, I want the activity to dump all data, that is get rid of all the strings and images that are in it. I figured the best way to do this was to just kill the activity. Well, I can't seem to figure out the callback for when the Back button is pressed. So, I have been trying to use the onPause() and the onStop() callbacks for the task but both ways force close my app. Here is the code: public void onPause() { this.finish(); } public

Handle force close?

我们两清 提交于 2019-11-27 03:49:54
问题 Is there a way to notify an activity/service of a force-close request right before it gets killed? I mean when the user hits the force close button in Menu > Settings > Applications > Manage applications > app name > Force Close . 回答1: I think the ActivityManager just kills the hosting process, so you may not be able to get any event/message/warning. To check you could create an app that has a single Activity that lets you know if onDestroy is called, and further if isFinishing is invoked.

Performing equivalent of “Kill Process Tree” in C++ on windows

北城余情 提交于 2019-11-27 03:14:17
问题 We have a C++ task that will fork a new process. That process in turn may have several child processes. If the task runs past an allotted time, we will want to kill that forked process. However, we don't want to orphan the processes it has spawned. We want them all to die. I have used Process Explorer and it has a "Kill Process Tree" option, similar to Windows Task Manager's "End Process Tree", so I'm guessing/assuming there is a public API to do this. Has anyone done this, or know of a

Kill Process Excel C#

谁都会走 提交于 2019-11-27 02:49:21
问题 I have to 2 process excel. For example: 1) example1.xlsx 2) example2.xlsx How to kill first "example1.xlsx"? I use this code: foreach (Process clsProcess in Process.GetProcesses()) if (clsProcess.ProcessName.Equals("EXCEL")) //Process Excel? clsProcess.Kill(); That kill a both. I wanna kill just one... Thank you. 回答1: The ProcessMainWindow Title will do it for you, it appends "Microsoft Excel - " to the name of the file: So essentially (quick code): private void KillSpecificExcelFileProcess