![]() |
|
#1
|
|||
|
|||
newbie question about killI have heard that killing a process is bad because it does not allow the process to clean up. I do not know what this means.
Does it mean that the memory allocated by the process is not released by the OS causing a huge memory leak? Or does it just mean that the process cannot catch the kill signal and therefore cannot do things like saving your work? What exactly happens when a process is killed? |
|
#2
|
||||
|
||||
|
Quote:
I am not up to speed on exactly how certain O/S'es may execute a process. But I believe that most O/S'es will run each process in its own seperate memory space but allocate data memory for the process from the heap. So, I do believe that there may be a chance of data memory not being "freed" when a process is abnormally terminated. Others may be able to give more detailed advice about this. Worse yet, is that the kill signal will just try to end the process and will not allow any saving of data, etc or allow the process to save data to a temporary file, etc. To me this is the true meaning of not "cleaning up." I can handle a reboot to reclaim stranded memory, but loosing work is just frustrating. BTW - what O/S are you talking about. The term kill tends me to believe that this is a *nix type system? __________________
The best damn Sports Blog period. |
|
#3
|
|||
|
|||
|
I am writing a program with a multiplatform toolkit (Qt) and did not realize that different OS's might kill differently. I'm targeting Linux and Windows.
The toolkit allows you to start and kill processes. The kill function in Unix sends the SIGKILL signal, and I think in Windows it is implemented similarly. |
|
#4
|
|||
|
|||
|
Well killing (-9) a process is usually a last resort in terminating a program, it shouldn't be used regularily. But there are many different severities of killing, from a meek SIGINT (interrupt: kill -2) or a polite SIGTERM (terminate: kill -15) to a violent SIGKILL (kill -9). See all that Unix supports by typing kill -l.
SIGTERM can be caught by your program, and thus can call a routine to tidy up, i.e. deallocate memory, close connections, pipes & files etc. Signals can be caught by the signal function: void *signal( int signo, void *func ) where func is a pointer to a function. Eg: CPP / C++ / C Code:
SIGKILL and SIGQUIT cannot be caught. Windows I don't know about, I don't code in it really. But if your compiler is ANSI compliant, it should be identical to Unix. Note, some OS's reset the signal handler once it's been used once. So for instance pressing ^C once for the above will work, but again will do the default OS thing, usually stopping it. So to prevent this, you should redefine signal() inside the signal handler! GF |
|
#5
|
||||
|
||||
|
Thanks for this Garth. This is very useful info. FYI, on the linux implementation, the signal interrupt function wants a int parameter which is the signal number.
I was wondering if anyone has any experience in signal handling with threads? My threaded program doesn't seem to like interupt handling routines. The threads are getting abandoned and/or interrupt routines are getting called multiple times. Is the sigaction function better to use than signal in this case? __________________
The best damn Sports Blog period. |
Recent GIDBlog
Writing a book by crystalattice
| Thread Tools | Search this Thread |
| Rate This Thread | |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Grouping data from MySQL with PHP - Newbie question. | giobbi | MySQL / PHP Forum | 12 | 27-Feb-2004 00:34 |
| question of practice | magiccreative | C++ Forum | 1 | 06-Feb-2004 07:17 |
| Problem with my Geforce video card | Shivs | Computer Hardware Forum | 2 | 30-Jan-2004 20:54 |
| a C input question | tmike | C Programming Language | 1 | 16-Sep-2003 02:31 |
| Code problem (a newbie question) | monkster87 | C++ Forum | 3 | 11-Aug-2003 12:46 |
Network Sites: GIDNetwork · GIDWebHosts · GIDSearch · Learning Journal by J de Silva, The