Re: how to send control-break or ctrl-c signal to a background process?

From: Bryan Dongray (btd_at_dongrays.com)
Date: 09/28/03


Date: Sun, 28 Sep 2003 14:10:05 -0500

walala wrote:
> Dear all,
>
> I have sent a job to run in background... However I now want to gracefully
> terminate it. This software has a good property that if I press
> control-break, or ctrl-c, it will enter into a graceful termination mode
> that it can still give me some partial useful information... so I don't want
> to use "kill -9" to kill it...
>
> instead, since it is run in background, I hope I can sent it a control-break
> or ctrl-c signal then it can output some partial useful information to the
> log file and then gracefully shutdown...
>
> Can anybody help me on how to do that?

Control-C is normally associated with SIGINT, which is most
likely be able to be sent using either:
        kill -2 $PID
        kill -INT $PID
but check your systems options for kill in the manual pages.

It is often likely that code traps the terminate signal (SIGTERM)
which is normally signal number 15, which is the default sent
by kill anyway, so if the code is usual, then:
        kill $PID
will send a TERM signal, and everything should be good.

You should only use "kill -9" in desperate situations, as
it gives the process no option but to stop immediately,
no tidying up of temp files, nor logging of anything.



Relevant Pages

  • Re: Detect End Process in application
    ... viruses that when you kill the process it starts right back up. ... So my previous answer "No it can't be done" might be wrong, all depends on why the user decides to use 'Taskman' to terminate an application, let me explain. ... The latter cannot be trapped, simply because no more user code will run in that process, the user portion of a process is cleaned up without returning a thread quantum to the process,. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: C# Threading, and suspending or killing a thread
    ... Other threads that are spawned like this go right back to zero CPU, ... the Process Explorer to kill it there. ... When you terminate a thread in a .NET application you should consider the whole appdomain doomed, as in, you should no longer keep it around. ... - deadlocks, if the thread locks internal resources it will never unlock them, thus blocking future threads from ever accessing the resources the lock protects ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: thread, threading; how to kill a thread?
    ... Python is embedded into C++. ... I was able to kill the threads ... nThreadId is the ID of the thread that you want to terminate (i.e. ... Calling this function will cause an exception to ...
    (comp.lang.python)
  • Re: OT: Planned Parenthood Christmas Gift Cards
    ... They kill 0 babies. ... They also convince some women NOT to terminate. ... that she be implanted with a frozen fertilized ovum, ... That's at least birth. ...
    (rec.gambling.poker)
  • Re: Unable to kill processes as administrator
    ... > running process (using task manager, or a third party kill utility). ... > terminate the process was to reboot the machine. ... > running by the named user, ...
    (microsoft.public.windows.server.general)