LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Desktop
User Name
Password
Linux - Desktop This forum is for the discussion of all Linux Software used in a desktop context.

Notices


Reply
  Search this Thread
Old 05-19-2024, 10:42 PM   #1
vipul.g
LQ Newbie
 
Registered: Nov 2023
Posts: 4

Rep: Reputation: 0
How to identify shutdown event in linux


In my Ubuntu application, I wanted to perform certain finalization for my application before the system is being shutdown. For that, I need to identify the shutdown event in my application.

From what I have read online, there are mainly two major solutions, that are being suggested.

using the 'PrepareForShutdown' dbus signal.
trapping the SIGTERM signal that is send to the running applications prior to shutdown.
However, I have tried both the ways and they don't seem to work for me. The handler that I m registering for 'PrepareForShutdown' never gets invoked.

For method 2, I have observed that my application does not receive SIGTERM signal, instead it receives some other signal a moment before being terminated using SIGKILL.

Can someone help me out, what should I be using to identify the shutdown correctly? I do not intend to read it from certain OS files, please provide an event based solution.
 
Old 05-20-2024, 12:04 AM   #2
lvm_
Member
 
Registered: Jul 2020
Posts: 984

Rep: Reputation: 348Reputation: 348Reputation: 348Reputation: 348
You can hook into systemd shutdown sequence: https://www.freedesktop.org/software...st/bootup.html (at the end).
 
Old 05-20-2024, 03:35 AM   #3
vipul.g
LQ Newbie
 
Registered: Nov 2023
Posts: 4

Original Poster
Rep: Reputation: 0
Quote:
Originally Posted by lvm_ View Post
You can hook into systemd shutdown sequence: https://www.freedesktop.org/software...st/bootup.html (at the end).

My application can be launched in multiple ways, and the above suggested way will be effective only If my application is launched as systemd service. I need a more generic solution to this.
 
Old 05-20-2024, 05:02 AM   #4
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 22,041

Rep: Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348Reputation: 7348
exactly what do you want? Either you can catch the signal (like sigterm), or hook the shutdown sequence (and send a signal to your app). But sigkill cannot be catched at all, there is no way to do that.
The normal shutdown process allows the processes to exit, probably your app cannot manage it very well. What*kind of process is it? (shell, python, java?). How was it started at all?
 
Old 05-20-2024, 05:31 AM   #5
lvm_
Member
 
Registered: Jul 2020
Posts: 984

Rep: Reputation: 348Reputation: 348Reputation: 348Reputation: 348
Quote:
Originally Posted by vipul.g View Post
the above suggested way will be effective only If my application is launched as systemd service
Incorrect, service can be used only for stopping or it could be a unit started before=shutdown.service
 
  


Reply

Tags
shutdown



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 to Run an event while another event is running in wxWidgets GUI? Sarathsankar Programming 11 10-24-2017 09:30 AM
LXer: Identify PCI and USB Wired and Wireless Driver in Linux – Identify PCI Driver. Ubuntu, Debian, LXer Syndicated Linux News 0 08-20-2014 07:21 AM
Print ID of important event which don't have associated click event raheel_com88 Linux - Server 1 05-31-2013 09:21 AM
How to read "identify" button press event, or state of "identify" blue led with IPMI? iav Linux - Server 0 01-27-2009 01:13 PM
Fire Event from other event in Visual C++ Express Edition chrisliando Programming 1 11-08-2007 05:12 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Desktop

All times are GMT -5. The time now is 06:59 PM.

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