Re: Is this program open?
Re: Is this program open?
- Subject: Re: Is this program open?
- From: Uli Kusterer <email@hidden>
- Date: Fri, 14 Apr 2006 12:21:37 +0200
Am 13.04.2006 um 20:01 schrieb John Stiles:
I'd much rather use the Carbon Process Manager then shell out to a
command-line tool. That sort of thing gives me the heebie-jeebies.
Then again, it seems like you need to have your "runs-as-root" bit
set to get all the info; I looked at Activity Monitor and found it
relies on a helper tool "pmTool". It has the "run-as-root" bit set
and uses apparently-undocumented Mach calls. Gah. I didn't expect
this to be hard :) Maybe I don't have a choice?
There's sysctl, which isn't undocumented. Here's what code I used
in Uli's Moose 3.0.x to detect whether the screen saver was running:
/*
========================================================================
=====
PROJECT: UlisMoose
FILE: ScreenSaverOn.c
PURPOSE: Detect whether the screen saver is running.
COPYRIGHT: (C) Copyright 2001 by M. Uli Kusterer, all rights reserved.
REACH ME AT:
E-MAIL: email@hidden
email@hidden
URL: http://www.zathras.de
========================================================================
== */
/*
————————————————————————————————————————————————————————————————————————
—————
Headers:
————————————————————————————————————————————————————————————————————————
—— */
#include <sys/sysctl.h> // You won't believe what I have to do to
find that darn screen saver...
/*
————————————————————————————————————————————————————————————————————————
—————
ScreenSaverOn:
Returns whether the screen saver is running *right now*
————————————————————————————————————————————————————————————————————————
—— */
int ScreenSaverOn()
{
int saverRunning = false;
int errval,
selector[3] = { CTL_KERN, KERN_PROC, KERN_PROC_ALL };
size_t oldlenp;
struct kinfo_proc* oldp = NULL;
errval = sysctl( selector, 3, NULL, &oldlenp, NULL, 0 ); // Get
Length of available data.
if( errval == 0 )
{
oldp = (struct kinfo_proc*) malloc( oldlenp );
if( oldp != NULL )
{
errval = sysctl( selector, 3, oldp, &oldlenp, NULL, 0 );
if( errval == 0 )
{
int x, max = oldlenp / sizeof(struct kinfo_proc);
for( x = 0; x < max; x++ )
{
if( strcmp( oldp[x].kp_proc.p_comm, "ScreenSaverEngin" ) == 0 )
{
saverRunning = true;
break;
}
}
}
free( oldp );
}
}
return saverRunning;
}
Cheers,
-- M. Uli Kusterer
http://www.zathras.de
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden