Take the 2-minute tour ×
Super User is a question and answer site for computer enthusiasts and power users. It's 100% free, no registration required.

I use Ubuntu 10.10, and I have a Python program (Mnemosyne) that I synchronize the data files using Dropbox. Here is my problem scenario. I leave the program running at home and go to work, but if I open the program at work and work on it the data file is changed, and I loose my progress at home when I exit (it automatically saves) when exiting.

I thought I could create a cron job to automatically close Mnemosyne every morning regardless of me remembering to do it or not, but if I use kill the program it exits without saving the datafile, and I end up with a tmp file and an error message when I restart it. Is there a better way of sending the exit signal to this program emulating me clicking file>exit menu option.

share|improve this question
    
How do you kill it? kill <program name>? –  Ignacio Vazquez-Abrams Jan 3 '11 at 1:45
    
how about running the programme in a shell (if its a cli app) or a nomachine session (if its gui(? –  Journeyman Geek Jan 3 '11 at 3:41
    
Yes I find the process ID and pass it to kill and kill it using process ID. –  biomed Jan 3 '11 at 6:30
    
kill - 15 appNameHere should send it the SIGTERM signal, which, if I remember right, asks to program to terminate itself. If it is well behaved, it should execute it's normal cleanup/save routines before exiting. –  Bobby Jan 3 '11 at 12:03
add comment

7 Answers 7

Try using a lower kill signal to the program such as 3 (SIGQUIT).

share|improve this answer
    
-3 is described as 'quit from keyboard', it sounds promising. –  invert Jan 3 '11 at 14:02
add comment

How about starting the program in a screen session at home so you can reconnect to it at work and have full control of what's happening?

http://www.howtoforge.com/linux_screen

share|improve this answer
add comment

Are there man pages on mnemosyne? Perhaps there is a close command in the docs that you could use in your cron job.

share|improve this answer
    
no The man doesn't state any way of doing this. –  biomed Jan 3 '11 at 6:27
add comment

By your description, I assume this is a GUI program running on an X server. Try wmctrl:

wmctrl -c "RegEx for Window Name"

From the man page: -c <WIN> Close the window <WIN> gracefully.

share|improve this answer
add comment

The correct answer to this depends on what your program supports. A well-behaved program should save all work and terminate gracefully when receiving the TERM signal, which is the default in kill, so I assume that that's the one you were trying. If the program doesn't tolerate that and doesn't offer any other way, for example over a control socket, you may be out of luck. In that case, try using a screen session or fix the program or use a different one.

share|improve this answer
add comment

This is highly application-dependent. If mnemosyne's authors have not foreseen this kind of situation and specifically created a "save and quit on receiving signal X" behavior, then you're pretty much stuck with having to manipulate its user interface to accomplish this.

However, as already suggested, the better solution would probably be to run mnemosyne under some form of display-sharing utility so that you can access the same session from both locations rather than shutting it down and restarting whenever you relocate. VNC is the GUI desktop sharing option I'm most familiar with, but there's probably a way to get X to let you do this at the application level (as opposed to than the whole desktop) and there are many other options out there these days which may work better for you.

If it were a command-line app, screen works wonderfully (I use it daily for just this purpose, giving me access to a single instance of mutt from multiple locations), but I don't think it handles GUI apps (the man page doesn't appear to reference "GUI" or "X").

share|improve this answer
add comment

As a general rule, the only way to close a program is a signal. As others have said, if it's not responding well to default kill (which sends SIGTERM) it's not likely to have the proper handler for other signals either. There is no 'kinder gentler' signal. All signals other than SIGKILL treat the process the same, running the handler if it has one, or killing the app.

That said, as a gui app, there is a very small chance it links to a library that you can control the app. You can try to see if you can send it messages with dcop, or d-bus. See http://dbus.freedesktop.org/doc/dbus-tutorial.html

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.