Project Home
Project Home
Wiki
Wiki
Discussion Forums
Discussions
Project Information
Project Info
Forum Topic - Get absolute fulll path of running process: (8 Items)
   
Get absolute fulll path of running process  
I am trying to extract the absolute full path of executing processes from the proc file system by reading the  file  the
 /proc/pid/as using devctl.

struct dinfo_s {
    	    procfs_debuginfo info;
    	    char pathbuffer[PATH_MAX];
    	};
    struct dinfo_s  dinfo;
    sprintf( buffer, "/proc/%d/as", pid );
	if ((fd = open( buffer, O_RDONLY )) != NULL)
	{
		status = devctl( fd, DCMD_PROC_MAPDEBUG_BASE, &dinfo, sizeof(dinfo), NULL );
		printf("path  %s \n", dinfo.info.path);
        }

But the path info I get is the relative path which is dependent on the launchpoint of the process i.e if an exe is 
launched as ./app1 , its full path shows as ./app1 instead of its absolute path .

How do I extract the absolute path of a running process ?

Re: Get absolute fulll path of running process  
Is this on 6.5?

The fullpath of the executable is stored on the auxv array on the 
stack.  Basically if you start with the initial_stack value from the 
process info,
then you can scan through...

argc
argv0
...
argvn
NULL
envp1
...
envpn
NULL
auxv

Then look for auxv[AT_EXEFILE]

On 2014-04-28 6:43 AM, atish bhowmick wrote:
> I am trying to extract the absolute full path of executing processes from the proc file system by reading the  file  
the /proc/pid/as using devctl.
>
> struct dinfo_s {
>      	    procfs_debuginfo info;
>      	    char pathbuffer[PATH_MAX];
>      	};
>      struct dinfo_s  dinfo;
>      sprintf( buffer, "/proc/%d/as", pid );
> 	if ((fd = open( buffer, O_RDONLY )) != NULL)
> 	{
> 		status = devctl( fd, DCMD_PROC_MAPDEBUG_BASE, &dinfo, sizeof(dinfo), NULL );
> 		printf("path  %s \n", dinfo.info.path);
>          }
>
> But the path info I get is the relative path which is dependent on the launchpoint of the process i.e if an exe is 
launched as ./app1 , its full path shows as ./app1 instead of its absolute path .
>
> How do I extract the absolute path of a running process ?
>
>
>
>
>
> _______________________________________________
>
> Technology
> http://community.qnx.com/sf/go/post110057
> To cancel your subscription to this discussion, please e-mail technology-networking-unsubscribe@community.qnx.com

Re: Get absolute fulll path of running process  
yeah i m using 6.5 , when u say scan thru starting from initial_stack address , are the subsequent members contiguous 
memory locations , if not how do i parse them since they r not accessible via any devctl structures such as 
debug_process_info 
Re: Get absolute fulll path of running process  
Just read the stack using read() on /proc/<pid>/as, once past argc then 
they are all char pointers until you hit the auxv array.

It may be useful to find it in a local process first, either in gdb or 
printing out the values.

On 2014-04-28 9:32 AM, atish bhowmick wrote:
> yeah i m using 6.5 , when u say scan thru starting from initial_stack address , are the subsequent members contiguous 
memory locations , if not how do i parse them since they r not accessible via any devctl structures such as 
debug_process_info
>
>
>
> _______________________________________________
>
> Technology
> http://community.qnx.com/sf/go/post110062
> To cancel your subscription to this discussion, please e-mail technology-networking-unsubscribe@community.qnx.com

Re: Get absolute fulll path of running process  
I wanted to clarify one more thing , the initial_stack which i read from the procfs_info structure using the devctl call
 , is that the value which needs to be used as offset during lseek .

lseek(fd,initial_stack,SEEK_SET); // OFFSET AS FILE TO initial stack 

// now read the as file 
read(fd,buf,stack size); 

now does buffer contain all the stack data which can be parsed for auxv ?
Also how much size should i read to get the stack ?
Re: Get absolute fulll path of running process  
On 2014-04-29 8:22 AM, atish bhowmick wrote:
> I wanted to clarify one more thing , the initial_stack which i read from the procfs_info structure using the devctl 
call , is that the value which needs to be used as offset during lseek .
Yes.
>
> lseek(fd,initial_stack,SEEK_SET); // OFFSET AS FILE TO initial stack
>
> // now read the as file
> read(fd,buf,stack size);
>
> now does buffer contain all the stack data which can be parsed for auxv ?
> Also how much size should i read to get the stack ?
The amount you must read will depend on the number of arguments, and the 
number of environment variables on the stack.
You should be prepared to demand read more as you scan for the aux vector.
>
>
>
> _______________________________________________
>
> Technology
> http://community.qnx.com/sf/go/post110079
> To cancel your subscription to this discussion, please e-mail technology-networking-unsubscribe@community.qnx.com

Re: Get absolute fulll path of running process  
Ok thanks for your help , i made some progress with the info u provided . 
One more thing does 6.6 version contain more/added proc filesystem functionality where information such as cmdline 
arguments & full path ca be readiily extracted from /proc/pid/as file thru some devctl cmds or other api s like we do 
for pid & stack address on 6.5 .

Pls let me know , in that case I wud go for 6.6 version .
Re: Get absolute fulll path of running process  
6.6 exposes /proc/<pid>/exename and /proc/<pid>/cmdline to simplify this.

On 2014-04-29 11:39 PM, atish bhowmick wrote:
> Ok thanks for your help , i made some progress with the info u provided .
> One more thing does 6.6 version contain more/added proc filesystem functionality where information such as cmdline 
arguments & full path ca be readiily extracted from /proc/pid/as file thru some devctl cmds or other api s like we do for pid & stack address on 6.5 .
>
> Pls let me know , in that case I wud go for 6.6 version .
>
>
>
>
> _______________________________________________
>
> Technology
> http://community.qnx.com/sf/go/post110088
> To cancel your subscription to this discussion, please e-mail technology-networking-unsubscribe@community.qnx.com