PDA

View Full Version : getting events




skumar2011
Mar 28, 2007, 07:18 AM
Hi Guys,

I have written two application on Mac,one is using carbon and another one is using cocoa. My both applications get launched and run as a process when Mac OS start because I m launching my applications from StartumItems. Now I don't want to allow any user to force quit my applications from activity monitor, if suppose user force quit the my applications at this point i want to restart the Mac machine automaticaly as soon as my applications gets quit.

Looking for the help.

Thanks,

Sunil



Nutter
Mar 28, 2007, 08:20 AM
The only way to do this is to have each application monitor the other, and take action if it detects that the other application has quit.

I'm not sure how to do this in Carbon, but in Cocoa's it's very easy: get the workspace notification centre from NSWorkspace and register to receive the notification called "NSWorkspaceDidTerminateApplicationNotification".

Wes
Mar 28, 2007, 08:32 AM
This application sounds a lot like a virus... :confused:

skumar2011
Mar 28, 2007, 09:38 AM
thanks guys for quick reply

in reply to the wes this is not a virus type of application

Nutter u mean to say i have to create a thread in my application in that thread i have to continously scan my second application is there in activity monitor or not,if not then it will restart the Mac machine. This will work fine if we simply quit the application form activity monitor and get the notification through NSWorkspaceDidTerminateApplicationNotification API but if i force quit then we won't get any notification through NSWorkspaceDidTerminateApplicationNotification API.

If I m wrong the please correct me.

Nutter
Mar 28, 2007, 10:40 AM
You will get a notification even if the application is force quit. I wouldn't recommend polling, that's not necessary.

There are uses for this kind of thing that don't involve viruses! However, you may want to consider just relaunching the apps if they are quit rather than restarting the whole system.

skumar2011
Mar 28, 2007, 10:52 AM
thanks Nutter
let me check what u said.
u don't have any idea in carbon?
How to implement same thing in carbon?
as u said in cocoa it is easy to implement.

actualy i hav developed the client and server kind of application using BSD and CFSocket and i m launching my client application through StartupItems. Whenever any particular client get disconnected ,i get the notification server side but which client got disconnect thats i don't know. I have posted this thing how to identify disconnected client on server side while using CFSocket but didn't get any reply.

Can u suggest me any link?

gnasher729
Mar 28, 2007, 12:20 PM
Hi Guys,

I have written two application on Mac,one is using carbon and another one is using cocoa. My both applications get launched and run as a process when Mac OS start because I m launching my applications from StartumItems. Now I don't want to allow any user to force quit my applications from activity monitor, if suppose user force quit the my applications at this point i want to restart the Mac machine automaticaly as soon as my applications gets quit.

That sounds rather nasty. Trying to implement some malware that starts when the Mac is started, observes each other and restarts the Mac when one is shut down so you can't get rid of it? Good luck.

Nutter
Mar 29, 2007, 07:09 AM
So the two apps aren't running on the same Mac? In that case, each app will have to spawn a separate process to monitor it. I have no idea how this is done in Carbon.

That sounds rather nasty. Trying to implement some malware that starts when the Mac is started, observes each other and restarts the Mac when one is shut down so you can't get rid of it? Good luck.

This wouldn't be very effective as malware. There's nothing to stop the user removing the applications from their startup items. I presume this is for a legitimate purpose, such as creating a server application that keeps itself running even in the event that it unexpectedly quits.