29. ágúst 2005

Kill everyone but me

If you think that programming is in anyway sissy, just consider this: "Programmers have to make a decision every day to create programs that perform tasks that could be considered 'Electronic genocide'". So think once, think twice.. think don't make fun of your fellow programmer! (and don't drive you car on the pavement)...

#include "KillEveryOneButMe.h"

OSStatus KillEveryone(Boolean KillFinderToo)
{
ProcessSerialNumber nextProcessToKill = {kNoProcess, kNoProcess};
ProcessSerialNumber ourPSN;
OSStatus status;
ProcessInfoRec infoRec;

Boolean processIsFinder;
Boolean processIsUs;
Boolean specialMacOSXProcessWhichWeShouldNotKill;
Boolean finderFound = false;

GetCurrentProcess(&ourPSN);

do{
status = GetNextProcess(&nextProcessToKill);

if (status == noErr){
//First check if its us
SameProcess(&ourPSN, &nextProcessToKill, &processIsUs);

if (processIsUs == false){
infoRec.processInfoLength = sizeof(ProcessInfoRec);
infoRec.processName = NULL;
infoRec.processAppSpec = NULL;

if (GetProcessInformation(&nextProcessToKill, &infoRec) == noErr){
processIsFinder = false;
if (infoRec.processSignature == 'MACS' && infoRec.processType == 'FNDR')
processIsFinder = true;

//since this is Mac OS X we need to make sure we don't quit certain applications
specialMacOSXProcessWhichWeShouldNotKill = false;
if (infoRec.processSignature == 'lgnw' && infoRec.processType == 'APPL'){
//don't want to quit loginwindow on Mac OS X or system will logout
specialMacOSXProcessWhichWeShouldNotKill = true;
}else if (infoRec.processSignature == 'dock' && infoRec.processType == 'APPL'){
//don't want to quit Dock on Mac OS X
specialMacOSXProcessWhichWeShouldNotKill = true;
}else if (infoRec.processSignature == 'syui' && infoRec.processType == 'APPL'){
//don't want to quit the SystemUI server on Mac OS X
specialMacOSXProcessWhichWeShouldNotKill = true;
}

if ( ((processIsFinder == false) || (KillFinderToo == true))
&& (specialMacOSXProcessWhichWeShouldNotKill == false))
(void)SendQuitAppleEventToApplication(nextProcessToKill);
}
}
}
}
while (status == noErr);
} // KillEveryone

Engin ummæli: