我正在尝试获取进程信息,进程名称工作正常,但当我尝试获取进程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 …… lol __whistles无辜___
解决方法 这条线NSLog(@"Process name: '%@' Process ID:'%@'",processID);
应该
NSLog(@"Process name: '%@' Process ID:'%d'",processID);/* change here ^ */
因为processID只是一个int而没有Objective-C对象
总结以上是内存溢出为你收集整理的Cocoa / Objective-C NSProcessInfo怪异全部内容,希望文章能够帮你解决Cocoa / Objective-C NSProcessInfo怪异所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)