terminate

Terminate a thread after an interval if not returned

三世轮回 提交于 2019-12-06 18:33:31
问题 I have a thread which grabs some data from network or serial port. The thread must terminate (or return false) if no data is received within 5 seconds. In other words, if running the thread is taking more than 5 seconds it must stop. I am writing in C#, but any .NET language is OK. 回答1: There are two approaches: 1. Encapsulated timeout The thread reading the data from network or serial port can measure time elapsed from its time of start and wait for the data for no more than the remaining

In a vbscript, how can i get the process id of the cmd.exe in which the vb script is running

五迷三道 提交于 2019-12-06 16:30:14
within a vb script, I want to assign a variable with the process id of the cmd.exe in which the vb script is running. Is there any command? Below is the example VB script procedure returning parent process caption and id: GetParentProcessInfo sCaption, sProcessId MsgBox "Parent Process Caption '" & sCaption & "'" & vbCrLf & "Parent Process Id '" & sProcessId & "'" Sub GetParentProcessInfo(sCaption, sProcessId) With GetObject("winmgmts:\\.\root\CIMV2:Win32_Process.Handle='" & CreateObject("WScript.Shell").Exec("rundll32 kernel32,Sleep").ProcessId & "'") With GetObject("winmgmts:\\.\root\CIMV2

Performing an action upon unexpected exit python

风格不统一 提交于 2019-12-06 16:09:04
问题 I was wandering if there was a way to perform an action before the program closes. I am running a program over a long time and I do want to be able to close it and have the data be saved in a text file or something but there is no way of me interfering with the while True loop I have running, and simply saving the data each loop would be highly ineffective. So is there a way that I can save data, say a list, when I hit the x or destroy the program? I have been looking at the atexit module but

Terminate a process by Cocoa

≯℡__Kan透↙ 提交于 2019-12-06 05:51:05
问题 If I terminate myself, just use the [NSApp terminate: nil] , it works very well. But if I want to terminate another process such as the active monitor, what should I do? To get the list of processes, I use NSArray* processlist = [[NSWorkspace sharedWorkspace] runningApplications]; Am I right? But how I can terminate a process by Cocoa, not use the kill or KillProcess(<#const ProcessSerialNumber *inProcess#>) or killpd or something like those, I just start learning Cocoa, so maybe I need some

How can I forcibly close a TcpListener

冷暖自知 提交于 2019-12-06 05:36:06
问题 I have a service which communicates through tcpListener. Problem is when the user restarts the service - an "Address already in use" exception is thrown, and the service cannot be started for a couple of minutes or so. Is there's any way of telling the system to terminate the old connection so I can open a new one? (I can't just use random ports because there is no way for the service to notify the clients what is the port, so we must depend on a predefined port) 回答1: Set the SO_REUSEADDR

The most reliable way to terminate a family of processes

房东的猫 提交于 2019-12-06 04:13:06
What is the best way to terminate a family of processes in Linux, if we assume that: arbitrary process in the family can get killed / terminates before we can start cleanup; as a result, if the child processes don't terminate, their PPID will be 1 processes can change process groups The particular scenario I'm looking at is Bash, but the more general technique, the better. Dan Cornilescu You may want to perform the killing (eventually via a script) in a different login shell to ensure you're not accidentally stopping/killing the very shell/script attempting to do the overall killing before it

How does a JVM running multiple threads handle ctrl-c, w/ and w/o shutdown hooks?

被刻印的时光 ゝ 提交于 2019-12-06 03:13:23
Could not find this answer online. When Ctrl+C is hit: When we don't have any shutdown hook, what happens to the running threads - do they each get hit with an InterruptedException? When we have shutdown hook(s), I know that the shutdown hooks get run in new threads in arbitrary order. But what happens to the existing running threads? Do they still each get hit with an InterruptedException? Thanks! The classic book "Java Concurrency in Practice" has a chapter (7.4) on the JVM shutdown, you should read that, but here are some relevant quotes: If any application threads (daemon or nondaemon) are

Rserve server: how to terminate a blocking instance (eval taking forever)?

若如初见. 提交于 2019-12-06 02:04:00
问题 I need to perform R eval s in a multi-threaded way, which is something Rserve provides quite well. But, if the eval of one instance takes too long, I need to be able to shutdown the instance which is computing the blocking eval. As far as I tested, the given instance will refuse to shutdown until the eval is done (apparently, it needs to fetch the result, before listening again). So here is my question: Is there a way get a java handle on the blocking instance (something like a Process object

How to customize uncaught exception termination behavior?

泪湿孤枕 提交于 2019-12-05 11:19:04
In g++ and clang++ (in Linux at least) the following typical message is shown after an exception is thrown and not catch (uncaught exception): terminate called after throwing an instance of 'std::runtime_error' what(): Bye For example in: #include<stdexcept> int main(){ throw std::runtime_error("Bye"); } How do I customize the error message while still having full access to the thrown exception? The documentation ( http://www.cplusplus.com/reference/exception/set_unexpected/ ) mentions set_unexpected (and set_terminate ) but I don't know how the unexpected_handle has actual access to the

Terminate a thread after an interval if not returned

。_饼干妹妹 提交于 2019-12-05 00:03:04
I have a thread which grabs some data from network or serial port. The thread must terminate (or return false) if no data is received within 5 seconds. In other words, if running the thread is taking more than 5 seconds it must stop. I am writing in C#, but any .NET language is OK. There are two approaches: 1. Encapsulated timeout The thread reading the data from network or serial port can measure time elapsed from its time of start and wait for the data for no more than the remaining time. Network communication APIs usually provide means to specify a timeout for the operation. Hence by doing