Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 08-27-2004, 02:37 PM   #1
Registered: Nov 2002
Posts: 57

Rep: Reputation: 15
how to define c terminate handler

Let say I'm opening a file for writing, filetemp.
In the case user terminate it by send SIGTERM.. blah blah.... signal to it.

eventually, the program will delete filetemp.

I don't want to implement signal handler, because the program may sometimes terminate abnormal eg w/o X, mem low....

Pls show me which manual I should refer.
The happier, you write the code for me.

Old 08-27-2004, 03:07 PM   #2
Senior Member
Registered: Jul 2004
Distribution: Ubuntu 7.04
Posts: 1,991

Rep: Reputation: 76
I don't think you can handle SIGTERM without a signal handler.
You could look at atexit(function), which will ensure that function after a normal exit (either a call to the exit() function or a return from main, but not in response to a signal).
My advice would be to write a handler for a lower-level signal, like SIGUSR1. Then you can just send it a SIGUSR1 (with “kill -SIGUSR1 PID”), and other signals will be uneffected.
Old 08-27-2004, 11:14 PM   #3
Registered: Nov 2002
Posts: 57

Original Poster
Rep: Reputation: 15
Then I just implement a SIGUSR1 handler.
Old 08-28-2004, 12:14 AM   #4
Registered: Mar 2004
Location: Massachusetts
Distribution: Debian
Posts: 557

Rep: Reputation: 42
If you're just worried about cleaning up your temp file, you could unlink it after opening it, and then you don't have to bother about how the program terminates.


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
SIGSEGV handler (segmentation fauld handler) myp Programming 8 03-08-2011 02:17 PM
How to terminate this command slpwkr Programming 4 03-28-2005 11:33 AM
terminate the connection ust Linux - General 1 03-19-2005 10:07 AM
<0>Kernel panic: Aiee, killing interrupt handler! In interrupt handler - not syncing mrb Linux - Newbie 2 01-09-2005 09:47 AM
How can I terminate an application? yangyiqi Linux - Software 7 12-10-2003 06:39 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:12 PM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration