LinuxQuestions.org
Go Job Hunting at the LQ Job Marketplace
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices

Reply
 
Search this Thread
Old 08-27-2004, 03:37 PM   #1
onnyloh
Member
 
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.

Thankyou
 
Old 08-27-2004, 04:07 PM   #2
rjlee
Senior Member
 
Registered: Jul 2004
Distribution: Ubuntu 7.04
Posts: 1,990

Rep: Reputation: 67
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-28-2004, 12:14 AM   #3
onnyloh
Member
 
Registered: Nov 2002
Posts: 57

Original Poster
Rep: Reputation: 15
Thankyou,
Then I just implement a SIGUSR1 handler.
 
Old 08-28-2004, 01:14 AM   #4
aluser
Member
 
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.
 
  


Reply


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 03:17 PM
How to terminate this command slpwkr Programming 4 03-28-2005 12:33 PM
terminate the connection ust Linux - General 1 03-19-2005 11:07 AM
<0>Kernel panic: Aiee, killing interrupt handler! In interrupt handler - not syncing mrb Linux - Newbie 2 01-09-2005 10:47 AM
How can I terminate an application? yangyiqi Linux - Software 7 12-10-2003 07:39 PM


All times are GMT -5. The time now is 09:16 AM.

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