NSProcessInfo *proc = [NSProcessInfo processInfo];
获取当前进程对象
以下是一些进程参数
NSProcessInfo *proc = [NSProcessInfo processInfo];
NSArray *args = [proc arguments];
NSLog(@”args : %@” , args);
NSDictionary *env = [proc environment];
NSLog(@”env : %@” , env);
int pid = [proc processIdentifier];
NSLog(@”pid : %d” , pid);
NSString *processName = [proc processName];
NSLog(@”processName : %@” , processName);
NSString *hostName = [proc hostName];
NSLog(@”hostName : %@” , hostName);
子进程管理 通过NSTask 调用shell 启动子进程
NSTask *task = [NSTask new];
task.launchPath = @"/bin/pwd";
task.currentDirectoryPath = NSHomeDirectory();
//NSFileHandle *output = task.standardOutput;
//NSFileHandle *input = task.standardInput;
[task launch];//执行 且子进程会重定向标准输出流到主进程
[task waitUntilExit];
NSLog(@"end");