Visit Our UNIX and Linux User Community


Problem on capturing system Shutdown


 
Thread Tools Search this Thread
Top Forums Programming Problem on capturing system Shutdown
# 8  
Old 08-27-2013
Quote:
Originally Posted by hakermania
So you claim that if I make a sync-safe function using the above sync-safe functions, then the handler will be executed?
Not necessarily, depending on how the program is killed. There are signals that cannot be interrupted. Further experimentation is required.

What I would do is create and close file when the program starts. When the signal handler is called, unlink() it. If the program cleans up properly, the file will disappear, if not, it will remain.

Quote:
And if this is true then how does the system determine:

a) Where in the memory the handler sits for each application
b) If the handler is sync-safe or sync-unsafe
It doesn't "determine" unsafe things. It doesn't "punish" unsafe code. It's the software interrupt itself that is unsafe, really...

It halts your main program, whatever it's doing, finished or not; then does a graceless jump to a temporary, limited stack space. It leaves whatever was happening, dangling. main could be inside printf or malloc already when you try and call them in your interrupt handler. That would be bad.

So to get around this, you have to talk directly to the kernel with system calls, instead of using your handy stdio libraries and such. This avoids tearing out your floor from under you by accident.
Quote:
What different does the system do instead of sending SIGTERM, waiting for the process to exit, and, after timing out, sending SIGKILL? Because it does something different, it not only sends SIGTERM, because if I send it, it just works.
I'd wonder if your disks are still mounted read-write by the time your program is killed. If they're not, you'll never see any changes even if your interrupt handler works.
# 9  
Old 08-27-2013
So if it doesn't determine whether my function is sync-safe or not, the function should run without many problems most of the time (as you see, the file is accessed nowhere inside the program, a simple sleep is being done)

The only thing that I want my real handler to do is to save one variable into one file that is closed during the whole execution of the program. That is the only place where the file is opened for writing and closed.

The variable is being updated once per second (adding one to itself), so the chance of it being accessed the wrong moment is very slight, and even if it does, I don't really care.

If I understand correctly you are advising me on how to make a function sync-safe, and thanks a lot for that, but that was not my initial question. My initial question was why the handler is not executed while it should. Function being async-unsafe has nothing to do as far as I can understand from your last reply.

And one last thing: If my disk is not writable when I receive the signal, how the heck am I going to do my cleanup? How are other linux applications do stuff like this?
# 10  
Old 08-27-2013
Quote:
Originally Posted by hakermania
And one last thing: If my disk is not writable when I receive the signal, how the heck am I going to do my cleanup? How are other linux applications do stuff like this?
It may be getting proper cleanup, I'm not sure. Daemons definitely do, I'm not so sure of random user processes that happen to be sitting around.

My suggestion would be to try the suggestion I made earlier, unlinking the file...

Previous Thread | Next Thread
Test Your Knowledge in Computers #901
Difficulty: Easy
Steve Jobs offered Linus Torvalds a job in 2000, on the condition that he stopped development on Linux.
True or False?

8 More Discussions You Might Find Interesting

1. Red Hat

shutdown system/myeclipse

Hi All, I have one situation to shut-down the system through shell script.I need script command to shut-down the system and process should end(safe-mode) the MyEclipse. (0 Replies)
Discussion started by: stsivaraj
0 Replies

2. Solaris

Shutdown system option

I am working on sunos solaris. I want to know which is good for system shut-down ? (3 Replies)
Discussion started by: Jitesh Varshney
3 Replies

3. Shell Programming and Scripting

Capturing awk's system(cmd) output

Hi everybody, I am working on a bigger awk script in which one part is comparing the size of two files. I want to evaluate which file is bigger and then just save the bigger one. I got it all working except for the part where I want to figure out which file is bigger; the one awk is currently... (2 Replies)
Discussion started by: iMeal
2 Replies

4. Windows & DOS: Issues & Discussions

system restarts after shutdown!!

Hello, from last few days my laptop is not whutting down properly.. when ever i ty to shutdown it restarts again.. what may be problem?? antivirus is updated till date.. and i use windows xp sp2.... regards, deepak. (5 Replies)
Discussion started by: smarty86
5 Replies

5. Shell Programming and Scripting

Sending mail on system shutdown

I want to only send a mail before my system goes for a shutdown or reboot. I don't want a mail when it comes up after a reboot or is normally started.. How can i achieve this? (2 Replies)
Discussion started by: proactiveaditya
2 Replies

6. Solaris

logs for system shutdown

I am working on a SUN T2000 machine with Solaris 10 running on it. When I checked the system this morning, I found it to be turned off. The lastreboot command showed that the system had been shut down the previous night. I want to find out how the system was shut down. I have run hardware health... (2 Replies)
Discussion started by: batman727
2 Replies

7. Shell Programming and Scripting

Shutdown a system by MAC?

Ok here is the problem we have 2 v440 with same IP address running solars 9. one remains on the other remains off. They are both configured exactly the same for redundant purposes for the software we use. This was the best/worst idea. Great because down time is only a mere minutes. The bad is the... (7 Replies)
Discussion started by: deaconf19
7 Replies

8. UNIX for Advanced & Expert Users

Capturing Oracle Shutdown error

Hi, Iam calling 3 sql scripts through one shell script 'rmia.sh'. Till now this was working fine, but last time while calling the SQL scripts, Oracle was down. But amazingly the exit status was '0' (success)!!! Below is the shell code: #!/usr/bin/ksh -x assign_file asql a.sql 1... (15 Replies)
Discussion started by: ganapati
15 Replies

Featured Tech Videos