• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Signal to a process started in Login session during logout

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

I start a process in background mode in user login session by placing it in user's profile. [I place a entry in .bash_profile to run a program in background].

Now if I choose logout from the left bottom menu of the GUI, what signal would be sent this my process?

I shall appreciate any help/comments/suggestion onto this.

Regards,
~Bhopal
 
Saloon Keeper
Posts: 27762
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Should be SIGHUP (as in Hang up).

There's a "nohup" command for situations where you want to keep running after logout, BTW.
[ August 12, 2005: Message edited by: Tim Holloway ]
 
Bhopal Singh
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I thought of the same and wrote a sample C++ program that catch the SIGHUP and in its handler it just flushes out all the information [Signal No, Signal code, the send process id etc] on a file and then exit by calling exit(0).
Now I compile this C++ and placed the Executable in my bash profile so that it can be started at login in background mode.

Now I logoout [Using my Desktop manager's logout button] and expected to see the SIGHUP info written on that file.

But unfortunately I did not find any file and hence assuming either it is some other signal or a process started in background mode in login shell do not recieve SIGHUP.

Any thoughts/suggestions?
 
Ranch Hand
Posts: 1923
Scala Postgres Database Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just guessing: SIGTERM, like in TERMinate?
[ August 13, 2005: Message edited by: Stefan Wagner ]
 
Ranch Hand
Posts: 139
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Bhopal,
You can try this:
add following line to your .bash_logout file,

killall -15 name_of_your_program

or

kill -15 pid_of_you_program


It will send SIGTERM to the process.
[ August 13, 2005: Message edited by: Deep Narsay ]
 
Ranch Hand
Posts: 1170
Hibernate Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would expect at least a SIGHUP first.
 
Tim Holloway
Saloon Keeper
Posts: 27762
196
Android Eclipse IDE Tomcat Server Redhat Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'd check for SIGTERM. Form a command line, I'd expect SIGHUP, but this is a GUI desktop shutting down its apps, so it's reasonable to expect that the GUI itself will trigger some sort of shutdown signals before the actual logout process begins.

Just guessing, since I've never had to deal with that sort of thing in the Unix world, but, like I said, reasonable.
 
Bhopal Singh
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks everybody for you response.

Let me rephrase my objective.

I'm writting an application [GUI in GTK] which can be started in following three manners:
1. At the user login [by placing a line myApplication& in user profile]. Placing the application at appropriate location so that it can be started at start up for KDE and GNOME is another possible solution bu this requires a no of hacks and work around and hence wanted to avoid this.
2. Manual invokation by the user by type on any shell [./myApplication <arguments>]
3. Or by a browser as a helper application in respose to a particular MIME type.

My objective is to ensure a graceful exit [wanted to perform some cleanup activities before my appliaction shutdown]of my application in following three scenario.

1. User logout.[I'm not sure which signal is sent when user logout using the Desktop manager's logout button]
2. User close the shell from which he has start my application.[I can catch sighup and can do the cleanup]
3. User closes the browser window which invoke my application as a helper application.[No idea at all how to handle this]

The solution I'm looking for should be generic enough to support various distribution of Linux [Redhat, SuSe and Mandrake atleast] and with all the possible shells the user can opt for.

I believe .bash_logout solution is applicable only if linux user using BASH as his shell. Please correct me if I'm worng.

I would appreciate any pointer/suggestion/solution to achieve the desired scenario.

Regards,
~Bhopal
 
Stefan Wagner
Ranch Hand
Posts: 1923
Scala Postgres Database Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
isn't WindowListner nClosing () (or similar - don't have my browser at hand the way to go?

[ August 17, 2005: Message edited by: Stefan Wagner ]
[ August 17, 2005: Message edited by: Stefan Wagner ]
 
Bhopal Singh
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Any linux guru with his expert comments/suggestions?
 
Stefan Wagner
Ranch Hand
Posts: 1923
Scala Postgres Database Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sorry - I have overseen the 'gtk'-note.
Gtk is c/ c++ - isn't it?

I used this way on a CLI-Application, but I think it will work in a gui-environment too:
In the main method I registered a signal-handler:

I guess it will work, but I'm not sure.

[ August 21, 2005: Message edited by: Stefan Wagner ]
[ August 21, 2005: Message edited by: Stefan Wagner ]
 
Bhopal Singh
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Stevens,

The million dollar question here is what all Signals[SIGHUP/SIGTERM ...] I need to handle in my code.
As described in my problem statement if I start my application in background mode while the linux user logs in, the application is not sent SIGHUP at the time of logout.
I found the link http://www.faqs.org/faqs/unix-faq/programmer/faq/ pretty useful and hence thought of sharing it.
 
Bhopal Singh
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

I've found the solution for 2 of desired scenarios in my original request.

Now I wanted to know how the Display manager [I'm interested in Gnome and Kde only] notifies the application started at Start Up [by configuring the Sessions Preference for Gnome and by placing your executable in .kde/Autostart folder for KDE] to shutdown when user logs out of the session?

I expected Signals SIGHUP or SIGTERM but not did not recieve any of them.

I would appreciate any pointers/suggestions.

Regards,
~Bhopal
 
reply
    Bookmark Topic Watch Topic
  • New Topic