Project Home
Project Home
Trackers
Trackers
Documents
Documents
Wiki
Wiki
Discussion Forums
Discussions
Project Information
Project Info
Forum Topic - Current process printf: Page 1 of 2 (13 Items)
   
Current process printf  
I want to be able to tell which process a piece of code is running in so that I can connect to that process to debug it.
  I can use printfs to output information from the running code.  Is there a call or method I can use to determine in 
which process I am running?

Thanks

Ant
Re: Current process printf  
Try this:
printf ("%d\n", getpid());

Ant Pace wrote:
> I want to be able to tell which process a piece of code is running in so that I can connect to that process to debug 
it.  I can use printfs to output information from the running code.  Is there a call or method I can use to determine in
 which process I am running?
> 
> Thanks
> 
> Ant
> 
> _______________________________________________
> QNX Momentics Getting Started
> http://community.qnx.com/sf/go/post8685
> 
Re: Current process printf  
Thank you!
Ant
Re: Current process printf  
> Try this:
> printf ("%d\n", getpid());
 
I am using this during the startup and getting the process ID printed as expected but the process is not listed when I 
run pidin after startup.  I suspect that the process is no longer running.  Is there a call that will turn that ID into 
a process name?

Thanks
Ant

Re: Current process printf  
Ant Pace wrote:
>> Try this:
>> printf ("%d\n", getpid());
>  
> I am using this during the startup and getting the process ID printed as expected but the process is not listed when I
 run pidin after startup.  I suspect that the process is no longer running.  Is there a call that will turn that ID into
 a process name?
> 

What would be the process name? Binary path? What is the point of that, you probably already know it.

Do you suspect your process is crashing? If so, have you checked if the process left a core behind? To determine where 
your core file would be located, see how is your dumper service started. The command line should reveal the destination 
path for cores.

If it is not crashing, add some more 'printf's to figure out if it's getting to the point you believe it does... I would
 start from there. 

Re: Current process printf  
No I am sure that the code is working as expected I just want to develop it further and don't know which process is 
running that code.  When I use pidin I see the short name, eg  opt/bin/antcode.  That is the information I want.  If I 
had written the code then I would know in which process it is running, but it is adopted code.  I want to know which 
process it is so that I can attach to the process with the debugger.

Ant
Re: Current process printf  
Ah!  I have found __progname which gives me a name.  I think it is the name of the process.
RE: Current process printf  
You can also do this:

printf ("%d %s\n", getpid(), argv[0]);


Steve Reid (stever@qnx.com)
Technical Editor
QNX Software Systems 
 
Re: Current process printf  
Ant Pace wrote:
> No I am sure that the code is working as expected I just want to develop it further and don't know which process is 
running that code.  When I use pidin I see the short name, eg  opt/bin/antcode.  That is the information I want.  If I 
had written the code then I would know in which process it is running, but it is adopted code.  I want to know which 
process it is so that I can attach to the process with the debugger.
> 

Then sorry, I do not understand what you are asking.

To try to just answer the question: in your main, you can do

printf("%s\n", argv[0]) 

and get the binary path.

But what confuses me is, if you can put printf in your code, compile it into a binary and run it, then how come you 
don't know which process is running that piece of code... if you could clarify a bit what exactly you are trying to do, 
maybe I could help.
Re: Current process printf  
I have joined a team and there are hundreds of source files and I haven't worked out a method of finding which code is 
in which process yet.  I see that there are clues in the makefiles.

argv[0] *does* print the name but this is like a standalone program.  I haven't used QNX or Unix based systems before.  
It feels as though the embedded RT system is starting a standalone program.  I suppose if it can be run from a console 
connection there is no reason that the embedded code can't do the same.  If that guess is right does that mean that the 
standalone program would run in a process that is then not seen with pidin after the program finishes?

Would it be normal for an embedded program to start a standalone program?  

Thanks for your help so far, I do appreciate it.

Ant