Hello
Some years ago I've written a command line programme to check unresponsiveness of specified process id. It uses undocumented API of window server. C source code is as follows. Tested to work under 10.5.8. nda 10.6.8. Not sure about later versions.
Regards,
H
/*
file
main.c
function
check whether the application with the give process id is responding or not
and print 1 if unresponsive, 0 otherwise.
compile
gcc -std=c99 -framework ApplicationServices -o unresponsive main.c
usage e.g.
./unresponsive 354
*/
#include <ApplicationServices/ApplicationServices.h>
#include <libgen.h> // basename
typedef int CGSConnectionID;
extern bool CGSEventIsAppUnresponsive(CGSConnectionID cid, const ProcessSerialNumber *psn);
extern CGSConnectionID _CGSDefaultConnection(void);
int main (int argc, char * argv[])
{
if ( argc != 2 )
{
fprintf(stderr, "Usage: %s pid\n", basename(argv[0]));
return 1;
}
OSStatus err;
ProcessSerialNumber psn;
pid_t pid = (pid_t) atoi(argv[1]);
err = GetProcessForPID(pid, &psn);
if ( err )
{
fprintf(stderr, "Failed to get PSN for pid %d: error = %d\n", pid, err);
return 2;
}
CGSConnectionID cid = _CGSDefaultConnection();
bool b = CGSEventIsAppUnresponsive(cid, &psn);
fprintf(stdout, "%d\n", b ? 1 : 0);
return 0;
}