LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
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 04-06-2001, 07:47 AM   #1
kca_alexander
LQ Newbie
 
Registered: Apr 2001
Location: India
Posts: 3

Rep: Reputation: 0

Is it possiable to write a program using Linux/C, which automatically saves all currently running applications before shutting down.

Advance Thanks
 
Old 04-06-2001, 08:52 PM   #2
crabboy
Senior Member
 
Registered: Feb 2001
Location: Atlanta, GA
Distribution: Slackware
Posts: 1,821

Rep: Reputation: 121Reputation: 121
Angry

Yes it's possible, but it is not needed. The shutdown command send a signal to init telling it to shutdown. init will send all process a SIGTERM signal. This signal notifies all the process that they need to shutdown. It's the process's responsibility to shut its self down and it has five seconds to do so. After five seconds, init will send a SIGKILL to all the process. This will unconditionally kill all the processes.

Now if programs do not catch the SIGTERM process and do what is necessary to exit, then one can say that the program is either poorly written or preparing to exit is not necessary. It's all up the person who wrote the program to exit correctly.

Hope this helps
 
Old 04-08-2001, 04:11 AM   #3
kca_alexander
LQ Newbie
 
Registered: Apr 2001
Location: India
Posts: 3

Original Poster
Rep: Reputation: 0
Yes I agree with you. But let’s take an example, Assume I am editing a document with some Word-processing application and it receives a SIGTERM signal, What happens! I think the application must popup with a confirmation window asking to save the document or even with a window asking for a filename. If user don't respond, As you told the OS waits for five seconds and will kill the application with out saving the document.

This is just my assumption, what are your view on this
 
Old 04-08-2001, 10:55 AM   #4
crabboy
Senior Member
 
Registered: Feb 2001
Location: Atlanta, GA
Distribution: Slackware
Posts: 1,821

Rep: Reputation: 121Reputation: 121
I see your point now. I missed it the first time since I have not run a GUI in years, and I'm not accustom to seeing that type of behavior.
The only think I can think of off hand, would be to write a daemon that could catch SIGTERM signals and wait for yes/no popup windows selecting yes to any that pop up. I have not touched X in a while, so I'm not really sure if it's possible.

Gary
 
Old 04-08-2001, 08:18 PM   #5
kca_alexander
LQ Newbie
 
Registered: Apr 2001
Location: India
Posts: 3

Original Poster
Rep: Reputation: 0
Yes that really helped Thank You.

Gary you know any web-sites about writing daemons and about X, so that I can work out your suggestion.

Thanks
 
Old 04-09-2001, 02:14 AM   #6
ugge
Senior Member
 
Registered: Dec 2000
Location: Gothenburg, SWEDEN
Distribution: OpenSUSE 10.3
Posts: 1,028

Rep: Reputation: 45
I'm not sure but isn't this supposed to work even in X.
If for example you didn't save before and actuaööy don't have name for the document then doesn't linux save an auto-save file with it's own name. Can this be?
 
Old 04-09-2001, 07:42 PM   #7
crabboy
Senior Member
 
Registered: Feb 2001
Location: Atlanta, GA
Distribution: Slackware
Posts: 1,821

Rep: Reputation: 121Reputation: 121
I don't know of any web sites, but I can recommend a great unix book. "Advanced Programming in the Unix Environment" by Stevens. As for X, the last I ever touched it was writing Sun openlook stuff about 4 years ago, and I can't remember what I used as a reference.

Gary
 
Old 04-10-2001, 04:28 AM   #8
salukibob
LQ Newbie
 
Registered: Mar 2001
Location: South of England
Posts: 9

Rep: Reputation: 0
Dealing with SIGTERM

The previous post by ugge was absolutely right. If (like in your example), a word processing document receives a SIGTERM, it will assume the system is shutting down, and should do an auto-save rather than prompting the user asking if they want to save. When the application is then restarted it should ask the user if they would like to revert back to the previous session. If a program, be it a GUI program, commandline or daemon doesn't do this, it should really be considered shoddy programming, and an alternative needs to be found. You shouldn't have to write your own daemon applications to deal with this, as it should already be covered.
 
  


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
how a father process know which child process send the signal SIGCHLD icoming Programming 10 07-20-2010 07:26 AM
Bash Scripting - child process affecting parent process mthaddon Linux - General 1 05-02-2004 01:19 PM
saving and not saving sessions on desktop ergo_sum Linux - Newbie 2 09-26-2003 07:27 AM
problem with binding process and than execute another process chapa Programming 0 08-27-2003 03:47 AM
Shutting Down PlatinumRik Linux - Networking 7 06-09-2003 07:18 AM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:43 AM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration