我刚开始学习Objective-C、Cocoa和iPhone开发。然而,我遇到了一个小问题,不太理解。
我正在尝试获取进程信息,进程名称可以正常工作,但是当我尝试获取进程ID时,情况变得奇怪起来。
这是我的一段代码,显然没有将任何内容输出到控制台:
NSProcessInfo *processInfo = [NSProcessInfo processInfo];
NSString *processName = [processInfo processName];
int processID = [processInfo processIdentifier];
NSLog(@"Process Name: '%@' Process ID:'%@'", processName, processID);
在这段代码块之后,所有其他的 NSLog 调用也会被忽略。而进程会继续运行并在控制台中声明有关 GDB 的信息:
Loading program into debugger… GNU gdb 6.3.50-20050815 (Apple version gdb-962) (Sat Jul 26 08:14:40 UTC 2008) Copyright 2004 Free Software Foundation, Inc. GDB is free software, covered by the GNU General Public License, and you are welcome to change it and/or distribute copies of it under certain conditions. Type "show copying" to see the conditions. There is absolutely no warranty for GDB. Type "show warranty" for details. This GDB was configured as "i386-apple-darwin".Program loaded. sharedlibrary apply-load-rules all Attaching to program: '/Users/jim/Documents/Xcode Projects/CS 193P/Assignment1B (WhatATool)/WhatATool/build/Debug/WhatATool', process 28700. (gdb)
我可能有点傻,在 Objective-C 中我从没有进行过处理... 哈哈 __吹口哨表示无辜__