Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cocoa/Objective-C NSProcessInfo weirdness

So I've just started digging into Objective-C, Cocoa, and iPhone development. I've ran into a little weird thing which I don't really get tho.

I'm trying to get process information, process name works fine, but things get weird when I try to also get the process ID.

Here's the piece of code I have, which evidently doesn't output anything to the console:

NSProcessInfo *processInfo = [NSProcessInfo processInfo];
NSString *processName = [processInfo processName];
int processID = [processInfo processIdentifier];
NSLog(@"Process Name: '%@' Process ID:'%@'", processName, processID);

After this block of code, all other NSLog calls are also ignored. And the process keeps running stating something about GDB, and I get this in the console:

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)

I'm probably a bit of an idiot here, but hey, I've never messed with Objective-C before... lol __whistles innocently__

like image 499
jimeh Avatar asked Mar 08 '09 21:03

jimeh


1 Answers

The line

NSLog(@"Process Name: '%@' Process ID:'%@'", processName, processID);

should be

NSLog(@"Process Name: '%@' Process ID:'%d'", processName, processID);
/*                          change here ^                          */

as processID is just a int and no Objective-C object

like image 191
epatel Avatar answered Oct 04 '22 12:10

epatel