How do I determine an application's process name?
Solution 1:
There is no way to solve this in the general case. Whatever mechanism you come up with, I believe that it will always be possible to write a process that will elude you, unless you modify the way that processes are launched in the first place in order to track them that way.
Upstart has to deal with exactly the same problem to track if daemons are still running, and upstart job authors have to specify details (the number of forks) for upstart to track. Given that upstart cannot manage it without help, I don't think that you can, either. And upstart is even in control of the way that processes are launched, which I don't think you are here.
I think the best you can do is what you are doing already. Looking at /proc/<pid>/stat
and /proc/<pid>/cmdline
is a reasonably general way, but still will not catch every case. The pgrep
command wraps this. If you aren't already using pgrep
, take a look at the pgrep manpage for options of things you can match against.
Having said all that, I'm not convinced that you really need to do this in the first place. If you can't track the process, then I don't see how Unity could do this either. Wouldn't a better approach be to eliminate the application crashes in the first place? I would look into details of why your applications are crashing (surely that's a bug somewhere?), rather than trying to work around it as you have described. I wonder if this only affects Unity-aware applications which are calling back to Unity for extra functionality via DBus?
Solution 2:
The xprop
command (followed by alt-tab to the relevant app window, then click once in the window) seems to do the trick for me.