I'm sending SIG_KILL to process on Linux, during the exit it encounters a memory bug and aborts generating core dump. I don't think it is possible on any Unix system, however this is what I observe. Is it possible for process killed by signal 9 to die from any other signal and to leave a core dump?
No, process can't catch SIGKILL but there is an option for a "process watcher" or wrapper.
Are you sure that not other processes are spawned to watch this process?
Related
I know that in most cases, it is impossible to ignore all signals. If it was possible for an application to ignore all signals, how would you stop it? Since you wouldn't be able to use SIGKILL or SIGSTOP...Not even sure if this question makes sense...
SIGKILL will end the process without it having any say in the matter.
When SIGKILL is send to a process, the kernel will not relay the signal to the process and call a signal handler it specified. Instead the kernel will simply immediately stop and destroy the process.
So, SIGKILL will always work. There is nothing the process can do to prevent it. It won't get any time to execute any code or do any cleanup. This is why you would usually try to send a SIGTERM first to ask the process to come to an end on its own and follow with a SIGKILL after a while only if the process didn't honor the SIGTERM request.
For SIGSTOP the matter is similar.
I have a long running Python script which is running in Visual Studio Code.
After a while the script stops running, there are no errors just this statement:
"fish: “/usr/bin/python3 /home/ubuntu/.…” terminated by signal SIGTERM (Polite quit request)"
What is happening here?
If a process recieves SIGTERM, some other process sent that signal. That is what happened in your case.
The SIGTERM signal is sent to a process to request its termination. Unlike the SIGKILL signal, it can be caught and interpreted or ignored by the process. This allows the process to perform nice termination releasing resources and saving state if appropriate. SIGINT is nearly identical to SIGTERM.
SIGTERM is not sent automatically by the system. There are a few signals that are sent automatically like SIGHUP when a terminal goes away, SIGSEGV/SIGBUS/SIGILL when a process does things it shouldn't be doing, SIGPIPE when it writes to a broken pipe/socket, etc.
SIGTERM is the signal that is typically used to administratively terminate a process.
That's not a signal that the kernel would send, but that's the signal a process would typically send to terminate (gracefully) another process. It is sent by default by the kill, pkill, killall, fuser -k commands.
Possible reasons why your process recieved such signal are:
execution of the process takes too long
insufficient memory or system resources to continue the execution of the process
But these are some possibilities. In your case, the root of the issue might be related with something different. You can avoid from a SIGTERM signal by telling the procces to ignore the signal but it is not suggested to do.
Refer to this link for more information.
Check this similar question for additional information.
I'd like to know if there is any chance that a thread executing any bad thing in a while(1) loop, gets killed by the kernel without the process gets informed.
I mean if the thread causes a SIGSEGV, the process is necessary affected so, that's not a case I'm interested in.
If it's killed by a SIGKILL:
kill -9 <pid>
Kernel may do that by itself in the case of Out of Memory (OOM) killer activation.
I am running a Linux program that uses a lot of memory. If I terminate it manually using Ctrl-C, it will do the necessary memory clean-up. Now I'm trying to terminate the program using a script. What is an elegant way to do so? I'm hoping to do something similar to Ctrl-C so it can do the memory clean-up. Will using the "kill -9" command do this?
What do you mean by memory clean-up?
Keep in mind that memory will be freed anyway, regardless of the killing signal.
Default kill signal - SIGTERM (15) gives application a chance to do some additional work but it has to be implemented with a signal handler.
Signal handling in c++
I am currently working on a project which has a daemon process that looks at a queue of tasks, runs those tasks, and then collects information about those tasks. In some cases, the daemon must "kill" a task if it has taken too long to run.
The explanation for SIGTERM is "termination signal" but that's not very informative. I would like to use the most appropriate signal for this.
What is the most appropriate POSIX signal number to use for telling a process "you took too much time to run so you need to stop now"?
If you're in control of the child processes, you can pretty much do as you please, but SIGTERM is the self-documenting signal for this. It asks a process to terminate, politely: the process chooses how to handle the signal and may perform cleanup actions before actually exiting (or may ignore the signal).
The standard way to kill a process, then, is to first send a SIGTERM; then wait for it to terminate with a grace period of, say, five seconds (longer if termination can take a long time, e.g. because of massive disk I/O). If the grace period has expired, send a SIGKILL. That's the "hard" version of SIGTERM and cannot be ignored, but also leaves the process no chance of neatly cleaning up after itself. Having to send a SIGKILL should be considered an issue with the child process and reported as such.
Usually you'll first send SIGTERM to a process. When the process recives this signal it is able to clean up some things an then terminate itself:
kill -15 PID_OF_PROCESS # 15 means SIGTERM
You can check if the process is still running by sending the 0 signal to it's pid.
kill -0 PID_OF_PROCESS # 0 means 0 :)
if [ "$?" == "0" ] ; then
echo "the process is still running"
fi
However, you'll need some grace period to let the process clean up. If the process didn't terminated itself after a grace period, you kill it using SIGKILL this signal can't be handled by the process and the OS will terminate the process immediately.
kill -9 PID_OF_PROCESS # 9 means SIGKILL, means DIE!