473,385 Members | 2,269 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Application Cleanup during Linux Shutdown

I'm trying to do some cleanup (write open files) when Linux shuts down. I thought the right method would be to trap SIGTERM and do the necessary processing. Here's my sample code:

Expand|Select|Wrap|Line Numbers
  1. #include <stdio.h> // for File I/O
  2. #include <signal.h> // for signals
  3. #include <unistd.h> // for sleep()
  4.  
  5. void handler(int signal)
  6. {
  7.     FILE *out=fopen("test.txt","at");
  8.     if (out)
  9.     {
  10.         fprintf(out,"got %d\n",signal);
  11.         fclose(out);
  12.     }
  13. }
  14.  
  15. int main()
  16. {
  17.     signal(SIGTERM,handler);
  18.     signal(SIGINT,handler);
  19.     sleep(30);
  20. }
  21.  
When I run this, and press Ctrl-C, it write "got 2" to test.txt. However, if I logout/reboot, nothing is written to the file.

Any help or ideas would be appreciated!

-Ron
Feb 4 '10 #1
1 2467
Ron,

When you run the program and hit Ctrl-C, you're sending a signal to it, and that's what is being saved in the file. The operating system knows nothing
about your program, so it won't run it.

To get the operating system to run your program, you need to look at the
manual page for inittab. It is the process for controlling the programs that
are run during startup and shutdown.

Hope this helps,

pikespeakcnc
Feb 4 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Jack | last post by:
It seems that if Finalize takes more than 2 seconds during the process shutdown, the process will just terminate anyway. How can I specifically tells GC that this guy's clean up does suppose to...
5
by: Pint | last post by:
Is there a way to prevent my web application from shuting down if I don't have access to machine.config? Thanks, Pint
2
by: gl | last post by:
I currently have an asp.net web app that starts a thread in the global.asax app start method. THe thread then runs for the duration of the app's life, changing data in the background. My...
6
by: diffuser78 | last post by:
I am using 8 computers on a small network. I have one Main computer which should be able to remotely start other computers. I used Wake on LAN to start them all. My Main computer is Linux. ...
0
by: Kevin A | last post by:
The problem is that the web application mysteriously shuts down (ending all sessions) due to a supposed 'configuration change'. By using ASP.Net Health Monitoring we can determine that the...
0
by: rohinichandrap | last post by:
Hi, I have a problem with the pdf files in one of my workspaces I am working with.This is during an upgrade from Visual studio 6.0 to Visual Studio .Net 2003. The workspace has two projects...
3
by: Joachim Klassen | last post by:
Hi all, if I accidentally use a TAKEOVER command with BY FORCE clause while primary and standby are in peer state I'll end up with two primary's (at least with FP10 and Windows). Is this works ...
9
by: jeff | last post by:
Hi All. I realize that when my Deployed winforms application starts, Windows needs to load the .net 2 framework before control is given to my application.... Is there anyway to either ... -...
69
by: MQ | last post by:
Hi all I am just wondering how most people implement cleanup in C functions. In particular, if the function opens a number of resources, these need to be released properly should an error occur...
22
by: Zytan | last post by:
I have public methods in a form. The main form calls them, to update that form's display. This form is like a real-time view of data that is changing. But, the form may not exist (it is...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.