Immortal process in Windows; no way to kill it - windows

I am writing a normal, innocent C++/Qt program in Windows 7/MinGW.
It is the second time in two days that after closing the program the executable remains among the active processes, and there is no way to kill it (I try both from the command line and from Windows Task Manager).
One inconvenience is that I cannot re-link my code, because the binary code cannot be overwritten, being running.

The reason is that the executable was running under the control of the debugger, and this protected the process against any attempt to kill it. Stopping it through the debugger has been successful.
I did not know that the debugger could shield a process from any external attempt to kill it so well...

Related

Start/stop process in embedded linux

I have my own embedded Linux system on PocketBeagle board. I have developed a simple gpio application in C that issues an on/off command to one of the pins of the connectors of the board. The application is called gpio_aa6 and located at /root.
The first challenge was to find a way to launch my application automatically after booting the board. I found two ways to do that; the first was to add an entry to etc/rcS directory. This entry is a simple script file that launches my application. The second way was to edit /etc/inittab file and add an entry to that file (::respawn:/root/gpio_aa6). In both these ways my application was launched successfully: but I am still not sure if this is the right way to launch my application automatically.
Then I came to the second challenge, how can I stop my running application, as the respawn re-launches the application if it's terminated?
I am communicating with the board in two ways; via a serial communication (using screen terminal) and via web sever (root#192.168.42.2). I have tried to use Ctrl+C, Ctrl+Z, Ctrl+\, but couldn't stop the program from being continue running. Then I used command "killall" with killsignals -9 or -15, it seems that the program is interrupted but it's launched again directly after that.
My application is to run infinitely, but I need to stop it sometimes to update it and re-launch it again.
Is there any suggestion how to overcome this problem?
Thanks.
Both solutions you have used are correct. I personally prefer the option of adding an init script to /etc/init.d though.
I believe the behavior that you observe that you apparently can't kill the program is because you are starting your program from inittab, with the respawn keyword, which precisely tells the init program to restart your application when it exits. If you actually check the PID of your application, you will see that it changes everytime you kill it.
Therefore, I would recommend you to use an init script instead, with which you can implement start and stop actions. See ./package/lldpd/S60lldpd for a basic example in Buildroot.

Is there a way to pause the make process and resume later?

I would like to pause this build process , shutdown my laptop and sleep for a while and resume later.Now I've found a linux command 'fg' that could work for me. But i'm not sure of how it's used and whether it will work in my case( i want to pause 'make' and shutdown my system).
Thanks in advance
First of all, makefiles are intended, almost, to do what you want: they should build only the missing or not up-to-date parts of a project. So, if you have a project made by 100 files, and start the build process, and after compilation of 50 files the build gets interrupted, on the next build invocation the process should restart, more or less, from where it was interrupted. This happens if the makefile is written well, and nobody issues a "make clean", of course.
Then you talk about the fg command, but its purpose is different from what you want: if you shutdown your computer, all the programs get stopped (and will not restart automatically). May be you can hibernate your laptop and, if yes, you don't need any further precautions.
Assuming you want to send a SIGINT to interrupt the process, the short answer is it depends on the process. For example, it's totally possible to stop an rsync process then resume it later. In order to stop a process then continue where you left off, you'd need a mechanism to store the last state the process was in.

Closing sub-processes spawned by CreateProcess

I'm working with CreateProcess to run a process/application of mine.
The purpose is to run it, do something, wait for some indication, and close it (Using TerminateProcess).
What I noticed is that this application/process creates sub-processes.
Additionally, when terminating the created process, the sub-processes do not terminate, and still remain for a period of time.
I wanted to ask if there's an option to somehow kill all the sub-processes with the main process.
It causes issues, since when I do CreateProcess again, there are leftovers from previous processes, and I think they're causing some issues.
I really appreciate your help!
Use Windows Job Objects. Jobs are like process groups; the operating system will take care of terminating all processes in the job once the job leader (your initial process) is terminated. This even works if the proess leader crashes.
When you create a process using CreateProcess you'll get a LPPROCESS_INFORMATION-pointer.
It contains the process handle. You'll need to close the processes manually, as there is no such thing as a process hierarchy as in Linux/Unix.
See here for CreateProcess and here for the PROCESS_INFORMATION-structure.

How to handle abnormal program termination in Perl on Windows

I have a Perl program on Windows that needs to execute cleanup actions on exit. I wrote a signal handler using sigtrap, but it doesn't always work. I can intercept Ctrl-C, but if the machine is rebooted or the program is killed some other way, neither the signal handler nor the END block are run. I've read that Windows doesn't really have signals, and signal handling on windows is sort of a hack in Perl. My question is, how can I handle abnormal termination the Windows way? I want to run my cleanup code regardless of how or why the program terminates (excluding events that can't be caught). I've read that Windows uses events instead of signals, but I can't find information on how to deal with Windows events in Perl.
Unfortunately, I don't have the authority to install modules from CPAN, so I'll have to use vanilla ActiveState Perl. And to make things even more interesting, most of the machines I'm using only have Perl 5.6.1.
Edit: I would appreciate any answers, even if they require CPAN modules or newer versions of Perl. I want to learn about Windows event handling in Perl, and any information would be welcome.
In all operating systems, you can always abruptly terminate any program. Think of kill -9 command in Unix/Linux. You do that on any program, and it stops instantly. No way to trap it. No way for the program to request a few more operating system cycles for a clean up.
I'm not up on the difference between Unix and Windows signals, but you can imagine why each OS must allow what we call in Unix SIGKILL - a sure and immediate way to kill any program.
Imagine you have a buggy program that intercepts a request to terminate (a SIGTERM in Unix), and it enters a cleanup phase. Instead of cleaning up, the program instead gets stuck in a loop that requests more and more memory. If you couldn't pull the SIGKILL emergency cord, you'd be stuck.
The ultimate SIGKILL, of course is the plug in the wall. Pull it, and the program (along with everything else) comes to a screeching halt. There's no way your program can say "Hmm... the power is out and the machines has stopped running... Better start up the old cleanup routine!"
So, there's no way you can trap every program termination signal, and, your program will have to account for that. What you can do is see if your program needs to do a cleanup before running. On Windows, you can put an entry in the registry when your program starts up, and remove it when it shuts down and does a cleanup. In Unix, you can put a file or directory name starting wit a period in the $ENV{HOME} directory.
Back in the 1980s, I wrote accounting software for a very proprietary OS. When the user pressed the ESCAPE button, we were suppose return immediately to the main menu. If the user was entering an order, and took stuff out of inventory, the transaction would be incomplete, and inventory would be showing the items as being sold even though the order was incomplete. The solution was to check for these incomplete orders the next time someone entered an order, and back out the changes in inventory before entering the new order. Your program may have to do something similar.

Run process during windows shutdown

I have a Win32 service, that needs to run a .NET executable on service stop (for cleanup reasons). I recently discovered that the cleanup never happens on shutdown, because the process creation gets blocked by OS. Does anyone know a way to override this? Process, I am spawning is not invasive and should only run a fraction of a second.
The only way I could find to do it was: pre-create a child process suspended, and them un-suspend it on shutdown.

Resources