2

I am a cocoa beginner and am trying to build an app for personal use, to manage local Apache/MySQL processes. I want to check if httpd (/usr/sbin/httpd) is running. I searched and found some hints pointing to NSTask and isRunning method, but could not get it to run.

How can I check to see if this process is running?

Besides, is this a reliable way to check whether OSX built-in Apache is running?

Thanks for any help.

4

1 回答 1

1

是的 NSTask 是检查或启动其他进程的可靠方法。以下代码必须帮助您实现所需。

NSTask *task = [[NSTask alloc] init];

[task setLaunchPath:@"/usr/sbin/httpd"];

if([task isRunning])
{
    NSLog(@"Hurray Apache running!!");
}

//If task is not running launch it yourself.

else 
{
    [task launch];

    if([task isRunning])
    {
        NSLog(@"Hurray Apache running!!");
    }
}

[task release];
于 2012-08-02T04:28:18.470 回答