kill

Automating Killall then Killall level 9

偶尔善良 提交于 2019-12-01 21:33:32
Sometimes I want to killall of a certain process, but running killall doesn't work. So when I try to start the process again, it fails because the previous session is still running. Then I have to tediously run killall -9 on it. So to simplify my life, I created a realkill script and it goes like this: PIDS=$(ps aux | grep -i "$@" | awk '{ print $2 }') # Get matching pid's. kill $PIDS 2> /dev/null # Try to kill all pid's. sleep 3 kill -9 $PIDS 2> /dev/null # Force quit any remaining pid's. So, Is this the best way to be doing this? In what ways can I improve this script? Avoid killall if you

Closing a minimized/iconized process from C#

一世执手 提交于 2019-12-01 21:33:21
Here's my issue: I need to close a process, already running, from a C# program. The problem is that the process now runs as an icon (minimized to taskbar), and unless the user opens it at least once (which will never happen on unattended machines), it'll never have a main window. The other requirement that I have is that the application be closed not killed . I need it to write it's memory buffers to disk - and killing it causes data loss. Here's what I tried so far: foreach (Process proc in Process.GetProcesses()) { if (proc.ProcessName.ToLower().StartsWith("myapp")) { if (proc

C - Get PID of process opened with popen

Deadly 提交于 2019-12-01 21:19:39
I have a program written in C, which opens another program using popen. I 'd like to get the pid of that program or some kind of handler for it, so as to kill it after a certain time limit, or if it exceeds some ram, and stdout limits. I think this must be done with ptrace, which needs the PID, which I don't know how to obtain. Just write your own implementation of popen that returns the PID. It's much less ugly than some crazy hackery around the existing popen . You can find source code to popen implementations all over the net. Here's one . You might also be able to use ulimits and other

Start Thread with a given execution time

青春壹個敷衍的年華 提交于 2019-12-01 21:04:27
My main process calls an external library method. This method sometimes hangs. I can not fix the external library because another company is responsible for it. I want to use a Thread for the library calls with a defined execution timer. When the method call takes to long, the Thread with the Runnable in which the method call is placed should stop and the main process should go forward. Main Thread wait Execute Thread start Start timer Thread When timer thread is finished kill Execute Thread Execute Thread stop Main thread resume Does anybody have some code this logic is for, a design pattern

Manage a .NET app to shutdown gracefully when terminated/killed

南笙酒味 提交于 2019-12-01 17:53:12
We have a .NET console app that has many foreground threads. If we kill the process using Task Manager or issuing killjob, kill from the command line in windows, is there a way by which we can gracefully shut down the application (adding manged code within the .net console app), something like having a function being called say TodoBeforeShutdown() that disposes objects, closes any open connections, etc. P.S. - I read the other threads and they all suggested different ways to kill the process, rather than my specific question, what is the best way we can handle a terminate process, within the

Is SIGSEGV special when generated by `kill`?

*爱你&永不变心* 提交于 2019-12-01 12:43:46
I know that SIGSEGV can't be ignored when the kernel uses it to report a memory access violation. But if I install a signal handler for SIGSEGV that does nothing, and then another process uses kill to send me that signal, will this behave the same as if I had used a "normal" signal (like SIGUSR1 ) instead? Grijesh Chauhan I have function that receive signal SIGSEGV but do nothing with it, does it mean that signal is ignored ? Yes, you caught the signal SIGSEGV and do nothing in handler, control returns. In general ignoring real SIGSEGV doesn't mean the error won't enable the program to

How to Kill Thread in C#?

佐手、 提交于 2019-12-01 11:37:11
I have a thread that opens a form of type MyMessageAlert. This form is a popup window that is opened when I call it. It has a timer which calls a method CloseWindow() after 30 seconds. m_messagAlert = new MyMessageAlert(); ParameterizedThreadStart thStart = new ParameterizedThreadStart(m_messagAlert.setMessage); Thread thread = new Thread(thStart); thread.Start(strMessage); //at this point, the MyMessageAlert form is opened. I have defined a list of type thread: public List<Thread> m_listThread; Each time that I create a thread, I add it to my list: m_listThread.Add(thread); When I close the

Android application Exit for home screen

≯℡__Kan透↙ 提交于 2019-12-01 11:23:04
I have develop android application,there I have Exit button in menu option.I want exit application and go to home screen when I press exit button. for that I have used following methods 1. System.exit(0) 2. finish() 3. android.os.Process.killProcess(android.os.Process.myPid()) 4. System.runFinalizersOnExit(true); these all methods direct to application my first page not to home screen.so what should I do for this?? please help me Firstly close in an android application is frowned upon because the back button and home button are already kinda giving you this functionality. But if you need to

How to kill a Thread with Objective C?

a 夏天 提交于 2019-12-01 11:13:23
I have a call to a third-party C++ library which I have put into its own thread (currently using NSThread). I would like to give the user the ability to stop the execution of that thread. (I am well aware of all the problems this might cause, but I still wish to do so.) According to Apple's Thread Programming Guide , there are possibilities in Cocoa to do so. Is this true for the iPhone, too, or do I have to rely on Posix threads to accomplish my goal? Cheers MrMage The correct way to stop your thread executing is to ask it nicely to stop executing. Then, in your thread, you listen for such

android如何让service不被杀死-提高进程优先级

∥☆過路亽.° 提交于 2019-12-01 10:53:47
1.在service中重写下面的方法,这个方法有三个返回值, START_STICKY是service被kill掉后自动重写创建 [代码]java代码: @Override public int onStartCommand(Intent intent, int flags, int startId) { return START_STICKY; }---------------- @Override public int onStartCommand(Intent intent, int flags, int startId) { // TODO Auto-generated method stub Log.v("TrafficService","startCommand"); flags = START_STICKY; return super.onStartCommand(intent, flags, startId); // return START_REDELIVER_INTENT; } 2.在Service的onDestroy()中重启Service. public void onDestroy() { Intent localIntent = new Intent(); localIntent.setClass(this, MyService.class); /