5

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.

4
  • How do you kill it? kill <program name>? Jan 3, 2011 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, 2011 at 3:41
  • Yes I find the process ID and pass it to kill and kill it using process ID.
    – biomed
    Jan 3, 2011 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, 2011 at 12:03

7 Answers 7

4

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

2
  • -3 is described as 'quit from keyboard', it sounds promising.
    – invert
    Jan 3, 2011 at 14:02
  • What I was looking for :) Nov 5, 2017 at 5:31
4

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.

3

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

2

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

1
  • no The man doesn't state any way of doing this.
    – biomed
    Jan 3, 2011 at 6:27
1

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.

1

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").

1

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

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .