-
-
Save softbrada/4890185831a2eafaba5492ffb79d7a3d to your computer and use it in GitHub Desktop.
Updated NonResponding
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* compile using this: | |
* gcc -framework Carbon -framework Foundation ./hung.m -o hung | |
* | |
* Referenced from https://apple.stackexchange.com/a/424763/260619 | |
* Original source code https://github.com/jksoegaard/NonResponding | |
* Original Author: jksoegaard | |
**/ | |
#import <Foundation/Foundation.h> | |
#import <Carbon/Carbon.h> | |
#include <ApplicationServices/ApplicationServices.h> | |
extern int _CGSDefaultConnection(void); | |
extern bool CGSEventIsAppUnresponsive(int connection, const ProcessSerialNumber *psn); | |
bool isNonResponding(pid_t pid) | |
{ | |
ProcessSerialNumber psn; | |
if( GetProcessForPID(pid, &psn) ) | |
return 0; | |
return CGSEventIsAppUnresponsive(_CGSDefaultConnection(), &psn); | |
} | |
int main(int argc, char *argv[]) { | |
if (argc < 2) { | |
printf("Usage: %s <pid>\n", argv[0]); | |
return 1; | |
} | |
pid_t pid = atoi(argv[1]); | |
bool is_responding = !isNonResponding(pid); | |
if (is_responding) { | |
printf("Process with pid %d is responding.\n", pid); | |
} else { | |
printf("Process with pid %d is not responding.\n", pid); | |
} | |
return 0; | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment