473,792 Members | 3,076 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Application Cleanup during Linux Shutdown

1 New Member
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 2487
pikespeakcnc
3 New Member
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
1612
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 take that long so that please wait until I finish my job gracefully?
5
2568
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
2210
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 question is what cleanup do i have to do for the thread when the app is stopped? Do i need to do anything at all? Should I put a threadname.abort in the application_end? I wasn't sure what cleanup to do. Thanks.
6
6836
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. Other 4 are Windows and 3 are Linux. How can I shutdown Windows box from my Main (Linux) ?
0
1348
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 application occasionally raises a "Application is shutting down. Reason: Configuration changed." event during normal application usage. The only known way to duplicate this event is to manually save the web.config, which correctly triggers the event as...
0
1163
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 A,B. Both the project's .exe,.map,.pdb files are placed in the same release folder. The project setting "Extensions to Delete on clean" under General project settings has .pdb extension also.
3
5678
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 as designed or a bug ? Manuals say that the standby will inform the primary about the takeover but will not wait for acknowledgement, so the primary knows about whats going on. In my eyes primary should either switch to standby or shutdown...
9
2990
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 ... - preload the .net 2 framework (windows startup or whatever) - splash a screen ... application loading ... please wait ... type of
69
3254
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 at any point in the function (as well as at the end if successful). C++ has exceptions, the only way I can see to do this neatly in C is to use goto statements. Is my method of implementing cleanup good, or are their better ways. Here is an...
22
3092
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 created / destroyed at user request). I can check form != null to prevent incorrect access. But, the form could disappear immediately after the check, before the method is run. Or someone could click 'close' when it's in the middle of an update. ...
0
9518
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10430
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10211
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10159
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9033
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6776
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5436
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5560
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2917
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.