Domanda

I'm working with some Objective-C++ code that launches a background process from my main app. The background process has no GUI, only runs for a moment, and must be run from the main app for it to be useful. This means I can't easily attach to the background process with Xcode or run it stand-alone, so I need to rely on output to stderr.

In this scenario, where should I be looking to find the stderr output?

More information in case I'm asking the wrong question: I am using an old version of Xcode (3.2.6) for reasons related to the age of the project I'm maintaining. I'm working on exception handling/reporting code, which makes it difficult to step through the code since GDB likes to catch exceptions rather than letting my code do it. The background process is only launched when a structured exception occurs within the main app.

Excerpt of the results of the lsof command on my main app, might be relevant:

COMMAND   PID  USER       FD     TYPE  DEVICE   SIZE/OFF  NODE NAME
<appname> 2788 <username> 0r     CHR   3,2           0t0   311 /dev/null  
<appname> 2788 <username> 1w     CHR   3,2      0t473379   311 /dev/null  
<appname> 2788 <username> 2w     CHR   3,2     0x6d545f8   311 /dev/null
È stato utile?

Soluzione

You can use the lsof command to figure out where a particular file descriptor has been redirected:

lsof -a -p <your pid> -d 0,1,2

When a background process is launched usually the child proccess is attached to the same standard streams as the parent process. For normal Cocoa applications by default you should be able to see that output in Console.app under 'all messages' or 'console messages'.

Before Mountain Lion you could also view the output of launchd services there, but I believe since then launchd redirects stdout and stderr to /dev/null.


This means I can't easily attach to the background process with XCode or run it stand-alone

If you can run the main application from Xcode you should be able to set the debugger to attach to child processes it launches.

The Xcode debugger can also be told to wait for a particular process to launch and to attach to it.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top