Re: Launching a process with Admin Privileges asynchronously
Re: Launching a process with Admin Privileges asynchronously
- Subject: Re: Launching a process with Admin Privileges asynchronously
- From: Alastair Houghton <email@hidden>
- Date: Wed, 1 Aug 2007 12:25:44 +0100
On 1 Aug 2007, at 10:01, Saritha A wrote:
I am trying to launch a process using
AuthorizeAndExecuteWithPrivileges() method. But problem with this
method is it does not respond to timer. When the process does not
respond for particular amount of time i want to kill that process.
But I am unable to implement it using above method. I came to know
that it is synchronous method so it does not respond to timer. Can
anyone suggest me how to launch a process with admin privileges
asynchronously or can anyone please suggest me any other alternative.
This isn't really a Cocoa specific question, as it stands anyway.
FYI, AuthorizeAndExecuteWithPrivileges() is *not* a synchronous
method; it launches the process and then returns. The reason you
aren't seeing a timer fire, assuming you're using an NSTimer or
similar, is that you aren't returning to (or even running) your
application's run loop. Instead, you're sitting in a loop calling
read(), which *is* synchronous---at least, unless you set the "pipe"
to non-blocking (AFAIK the pipe, by the way, isn't a pipe at all;
it's actually a UNIX socket... pipes are unidirectional).
There are lots of ways to do what you're asking. Since this is a
Cocoa list you're asking, one way might be to create an NSFileHandle
and use its -readInBackgroundAndNotify method (or similar), rather
than calling read() in a loop.
You could also use CFStreamCreatePairWithSocket() to create a read
stream and a write stream; CFReadStreamRef and CFWriteStreamRef are
toll-free bridged with NSInputStream and NSOutputStream respectively,
so you can use the resulting Core Foundation stream objects as if
they were Cocoa NSInput/OutputStream objects. You'll want to use
them in run-loop scheduling mode, if you want timers to fire whilst
you're reading/writing them. Take a look at
<http://developer.apple.com/documentation/Cocoa/Conceptual/Streams/
index.html>
for more information.
There are probably plenty of other approaches you could use in Cocoa
as well. I believe there are various third party frameworks for
working with sockets, for example.
Kind regards,
Alastair.
--
http://alastairs-place.net
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden