Finding the full path of a process binary using /proc

Hello,
I have an application where I need to monitor whether a certain other process is running. I'm using the /proc filesystem and an ioctl call - namely, PIOCPSINFO - to fetch process information into a prpsinfo_t, then use either the pr_fname field for the base name of the process executable or pr_psargs for the full launch command line - the first argument being the executable name. However, I see that if I launch something like "man chmod" in the shell, the pr_psargs for that process is "man chmod", not "/usr/bin/man chmod", thus making it hard to distinguish between binaries which have the same base name, but can be run from different locations (e.g. /usr/ccs/bin/make and /usr/local/bin/make). Is there some way to find out the environment (actually, the PATH variable) that a process has been run with? I see there's an 'uintptr_t pr_envp' in pr_psinfo_t that is supposed to be the "address of initial environment vector". How can I use that?

I believe you have to open the processes 'map' file and use the envp address
as an index into that file. It's the address inside the target process.
The problem is that (until recent S10 release) the kernel doesn't actually
remember the pathname that was used to open the binary. There is
no guarantee that the binary is actually the first one on the search path
that's just a convention followed by most shells. If the program was
explicitly exec'ed by another program, it might not even be on the search path.
However, you can get an open file descriptior on the executable binary
by using a /proc interface.
If you know the file that you are looking for there is another way:
- open the binary you're looking for (/bin/ls)
- get device/inode of this file (using stat)
- seach processes that "look" like they might be the one you want
- for each one:
get FD of binary using /proc
stat the FD to get device/inode
compare to device/inode from the binary you're looking for
This is a bunch more work, but it's the only way to be sure.
It's better to avoid the whole mess and find a better way.
it's better to let an OS utility do the /proc mucking. They are
more likely to get it right. /proc is pretty complicated. And if you
using it ways that haven't been tested before, you can find
interesting problems.
You could just run 'ps|grep' or the 'pgrep' command.
Here is a short demo of how to compare inodes:
% ls -i /proc/$$/object/a.out
97634 /proc/9120/object/a.out <--- always called a.out, no matter the binary name
% ls -i /bin/bash
97634 /bin/bash <-- notice the same inode number
This means /bin/bash is the executable being used for my current shell.

Similar Messages

  • How do i see what the full path of a redirected link is?

    www.website.com/folder/ <--- how to seethe blank space that isnt shown
    i am trying to find the full path for a url that only supplies the folder. im writing a java (not an applet) program that is trying to use a link that only knows the folder at runtime. im trying to perform a GET command to access the page that browsers seem to have no trouble finding.
    ive tried adding index.htm/html and default.htm/html to the end of the url but no luck. the get fails.
    any advice?

    mmmh...
    plenty of other forums you can try as well: http://www.laughinghens.com/knitting-forums

  • Managed Metadata Refiner and Displaying the Full Path

    Does anyone know how best to work with the metadata refiner for a column that is set to show the full path of the tag?  We need to display the full path for this column when used in various views; however, when the full path is shown is the search refiner
    it is too long and run out into the search results.  (see picture)
    Is there a way to only show the tag name and not the full path to the tag within the refiner but still have it show the full path within libraries?  Thank you

    Daniel,
    Thank you for this article.  It looks like it would help, but when I replace the xslt with what's suggested in the article my refinement panel disappears.  Perhaps I'm not implementing it correctly.  I have a couple of managed metadata refiners
    listed as the first two refiners in the panel in addition to the usual ones such as author, date, site.
    What I did is that I replaced the xslt inside the <a> tags with the xlst mentioned in the article.
    <a class="ms-searchref-filterlink" href="{$SecureUrl}" title="{$RefineByHeading}: {$UrlTooltip}">
    <xsl:value-of select="Value"/></a>
    with
    <a class="ms-searchref-filterlink" href="{$SecureUrl}" title="{$RefineByHeading}: {$UrlTooltip}">
    <xsl:variable name="PartOfValue">
    <xsl:call-template name="substring-after-last">
    <xsl:with-param name="string" select="Value" />
    <xsl:with-param name="delimiter" select="':'" />
    </xsl:call-template>
    </xsl:variable>
    <xsl:variable name="PartOfTooltip">
    <xsl:call-template name="substring-after-last">
    <xsl:with-param name="string" select="$UrlTooltip" />
    <xsl:with-param name="delimiter" select="':'" />
    </xsl:call-template>
    </xsl:variable>
    <xsl:choose>
    <xsl:when test="($FilterCategoryType = 'Microsoft.Office.Server.Search.WebControls.TaxonomyFilterGenerator') and ($PartOfValue != '')">
    <xsl:if test="not(contains($PartOfValue, '…'))">
    <xsl:value-of select="$PartOfValue"/>
    </xsl:if>
    <xsl:if test="contains($PartOfValue, '…')">
    <xsl:value-of select="$PartOfTooltip"/>
    </xsl:if>
    </xsl:when>
    <xsl:otherwise>
    <xsl:value-of select="Value"/>
    </xsl:otherwise>
    </xsl:choose>
    </a>
    Is this correct? Thanks for the help.
    Matthew

  • How do I obtain the full path string for my file?

    Many Mac applications are particularly bad at guessing what folder I want to grab a file from.  As a result, I waste a great deal of time fishing all through my directory tree in order to put and take my files in and from the right location.  It does seem to be better is some applications but still the nuisance is an issue.  Of course in Windows this can happen too except there I have a workaround to help out the foolish applications.  I can copy the full literal path to the clipboard from Explorer.  Then when the file access dialog comes up I can paste the full literal path ahead of the filename and snap to the correct folder.  On my mac, I have had mixed success approximating this strategy.  Sometimes, if the target folder isn't empty, I can use the Finder to browse to the target folder and open the Get Info dialog for a file and copy the full path from within that dialog.  This does not work though when the folder is empty and Mac does not support the create new text file on the fly feature.  Furthermore, I have noticed some strange behavior even when I do have the full path copied.  One such example is using TextEdit, pasting this full path has resulted in the application using the full path as a really long filename for the new file which still resides in the folder the application incorrectly assumed.
    There is a list box in most Mac file access dialogs with _some_ of the recent folders I accessed listed for quick selection but nine times out for ten the folder I just came from isn't among them.  That detail really surprises me.  Do regular Mac users have habits that prevent problems like this, or is there a better way to _bank_ a literal folder location I know I'll need to use soon and often, or do I just need to get used to fishing for folders during file access?

    Welcome to Apple Support Communities. Most of us are users here.
    Create folders and drag those 'frequently used' folders to the left-hand FAVORITES column/sidebar in Finder.
    Then just drag your files to the destination folders, or click on them to select them as destinations from your applications.
    When you no longer need these folders, right-click to remove them from the FAVORITES sidebar.
    They'll still be in the original location where they were created, just no longer visible in the sidebar.
    Another thing to note is that the full path of your current destination is shown at the bottom of the screen in Finder. In this case Macintosh HD, Users, (Home folder name), Desktop.

  • How to get the full path of a file

        If the user selects a file through a browse button, Is there a way, I can get the full path of the file. The file can be from his local hard drive as well.. Can someone advise    

    To upload multiple files (example is for 3), try something like this.
    == Form section ==
    There would be three(3) file form fields for the selection of a file/document to upload, which
    each being uniquely named.
    <div style="clear: both;">
    <cfinput type="file" name="upload_01" dir="ltr" lang="en" size="70" xml:lang="en">
    </div>
    <div style="clear: both;">
    <cfinput type="file" name="upload_02" dir="ltr" lang="en" size="70" xml:lang="en">
    </div>
    <div style="clear: both;">
    <cfinput type="file" name="upload_03" dir="ltr" lang="en" size="70" xml:lang="en">
    </div>
    == Processing section ==
    Checks to see if any files / documents were selected for upload. If none were, then
    displays an alert indicating as such. If at least one file/document was selected, then
    the process would process the upload.
    <cfif isdefined('form.upload_01') and trim(form.upload_01) eq "" and
    isdefined('form.upload_02') and trim(form.upload_02) eq "" and
    isdefined('form.upload_03') and trim(form.upload_03) eq ""
    >
        <p>Did not select any files to upload</p>
    <cfelse>
        <cfif isdefined('form.upload_01') and trim(form.upload_01) neq "">
            <cffile
                action="upload"
                destination="C:\path\to\upload\files\to"
                filefield="upload_01"
                nameconflict="overwrite"
                accept="
                  application/msword
                , application/vnd.openxmlformats-officedocument.wordprocessingml.document
                , application/vnd.ms-excel
                , application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
                , application/pdf">
                <cfcookie name="upload_01_doc" value="#cffile.serverfile#">
                <cfcookie name="upload_01_doc_ext" value="#cffile.serverfileext#">
        </cfif>
        <cfif isdefined('form.upload_02') and trim(form.upload_02) neq "">
            <cffile
                action="upload"
                destination="C:\path\to\upload\files\to"
                filefield="upload_02"
                nameconflict="overwrite"
                accept="
                  application/msword
                , application/vnd.openxmlformats-officedocument.wordprocessingml.document
                , application/vnd.ms-excel
                , application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
                , application/pdf">
                <cfcookie name="upload_02_doc" value="#cffile.serverfile#">
                <cfcookie name="upload_02_doc_ext" value="#cffile.serverfileext#">
        </cfif>
        <cfif isdefined('form.upload_03') and trim(form.upload_03) neq "">
        <cffile
            action="upload"
            destination="C:\path\to\upload\files\to"
            filefield="upload_03"
            nameconflict="overwrite"
            accept="
                  application/msword
                , application/vnd.openxmlformats-officedocument.wordprocessingml.document
                , application/vnd.ms-excel
                , application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
                , application/pdf">
            <cfcookie name="upload_03_doc" value="#cffile.serverfile#">
            <cfcookie name="upload_03_doc_ext" value="#cffile.serverfileext#">
        </cfif>
        <cflocation url="completed.cfm" addtoken="no">
    </cfif>
    == Completed section ==
    Can confirm to the person what files were actually uploaded, by displaying file name and file extension.
    You can you use the file extension information to display a respective icon for the file type.
    <cfoutput>
    <cfif isdefined('cookie.upload_01_doc')>
    01. #cookie.upload_01_doc# - #cookie.upload_01_doc_ext#<br /></cfif>
    <cfif isdefined('cookie.upload_02_doc')>
    02. #cookie.upload_02_doc# - #cookie.upload_02_doc_ext#<br /></cfif>
    <cfif isdefined('cookie.upload_03_doc')>
    03. #cookie.upload_03_doc# - #cookie.upload_03_doc_ext#<br /></cfif>
    </cfoutput>
    Leonard B

  • Need Help in finding the Menu Path's for the below topics

    Hi,
    Where can i get the menu paths for the below topics in SAP syste. I have searched in the system,But couldnot find the Menu Path's for the below topics.Kindly help me in finding the configuration Path for the below...
    1)Public tendering process
    2)Grants Management
    3)Tax & Revenue management
    4)Public sector accounting --> Budget formulation, preparation, execution & Monitoring.
    Thanks
    Rajitha M

    Hi,
    Check for the relevant path in IMG in Public Sector Management.  The prerequisites being configuration of Financial accounting
    sub modules.
    Best Regards,
    Sadashivan

  • Finding the directory path in java

    I need to check if a file exists or not before an action is taken. I used File class to get the handle of a file and and then used exist() function to check if it is there. But this function needs to full path to that file. I need to find a directory path at runtime as the application is deployed in different environment and wouldn't know the directory path in each environment. Could somebody help me on this. Thanks,

    fBut this function
    needs to full path to that file. I need to find a
    directory path at runtime as the application is
    deployed in different environment and wouldn't know
    the directory path in each environment. Well, that can only you know where this file is on the different platforms. So maybee you can provide it as a user-input, a parameter to the program or be set in a settings-file which the program reads.
    If you want the full path to the current directory where the java program runs, this works:
    File f=...;
    String absPath=f.getAbsolutePath();
    File absPathFile=new File(absPath);Gil

  • How do I see the full path in Yosemite's spotlight?

    How do I see the full path in Yosemite's spotlight? (cmd shows only partial path)
    Seeing the full path would make work much easier finding my articles which I have put in distinct catalogues.

    CazooMAC,
    Holding ( Command ) to show the path of a file that is displayed at the bottom of the preview pane in Spotlight is the only way to display the path in the Spotlight app its self.
    If you hold ( Command ) and double click the item you are looking to get a path of it will open that items containing folder in Finder. From there you can get the full path using a bunch of different methods. An Example would be using Finders Get Info option. The Keyboard shortcut is ( Command ) ( I ).
    There is another thread that covers the topic of getting a clean path in Finder. Or basically a path that one doesn't have to type out manually, without those little arrows in between folders. It can be found here: How to get a clean file path in OS X Yosemite?
    My Suggestion to get a clean path there is as follows:
    Another way you can get the path, and yes I'm aware its cumbersome, is you can open the "Go to Folder" window and drag your folder or file into it and it will give you the path. Free of modifiers and without opening another application.
    I find it works best if when you start there is no Finder windows open. If you leave one open you just have to open another one as it doesn't let you drag and drop from the one with the "Go to Folder" window in it.
    Finder has to be Active > Select Go ( Menubar ) > Go to Folder...
    Or you can use the keyboard shortcut ( Command ) ( Shift ) ( G )
    At this point I like to clear out the address field as if there is anything in there it will stay.
    Next Open a new Finder window.
    Examples on how to: Select File > New Window, or the keyboard shortcut ( Command ) ( N )
    Find the File or Folder your interested in then drag and drop it in the Address Field of the "Go to Folder" window and it will give you the path.
    If you would like to send Apple feedback about this you can do so here: https://www.apple.com/feedback/macosx.html
    Hope that helps,
    Weston

  • How can I find the real path to servlet class

    Hi,
    I am facing an issue. Am in the process of creating a filter which would send a Last-modified along with the header. For this I will be checking the is-modified-since
    header and lastModified date of the file.
    The problem I am facing is that after taking the file part from the request and checking
    the lastmodified date, it gives error. This is because i use,
    String real_path = getServletContext().getRealPath(request.getServletPath());
    and it would return the path to servlet-name and not to servlet-class, since servlet-name
    is not physically present. It would return an error value.
    Is there any way which I could find the real path to my servlet class file ?

    Remember you should not take the last mnodified date
    of the class file or the jar file that contain the
    class as the value for the getLastModified method
    becouse the last modified date that should be used in
    the caching is the last modified date of the dynamic
    content that the servlet is about to prodice.
    The same class file will produce different content
    for different requests if not why do you use
    servlets you can directly use the static contentThanks for a valuable remark.
    Hence our getLastModified() often returns System.currentTimeMillis() result.

  • How can I show the full path in terminal?

    By default I only see the current folder
    How can I toggle it so that I see the full path instead?
    I say toggle - I'd like to switch on and off
    Thanks
    Omar

    @arthur, awesome! thats better than what i was trying to do!
    i only wanted to get the path so that i could cd to it
    but then i have to add quotes around because of spaces
    the method u suggested escapes all required chars and means i can just type cd and then drag the folder and then press enter
    @barney: super helpful - i need to re-remember my unix commands. lol

  • How to find the menu path ?

    Hi all,
    I have one doubt how do we find out the correct menupath if we know the t-code ?
    for example, SE11 -DDIC
    we can also obtain the same DDIC screen via menupath from SAP main screen.
    if I know only t-code.how can i find out the menupath ?
    thnks and rgds,
    raghul

    Hi Raghul,
      You can go to the transaction search_sap_menu
    for finding the menu path.
    check this link:
    http://www.sap-basis-abap.com/sapgeneral/system-path-and-transaction-code-mapping.htm
    Hope this helps you.
    Regards,
    Chandra Sekhar

  • How to get the full path of the fmx's directory.

    Hi all,
    I will ship my project to a customer. So I must install forms runtime at the customer's machine.
    I put all of the fmx files of my project into a certain directory at the customer's machine, and I create a desktop shortcut of the forms runtime. In the "start in" field of the shortcut property I put the full path of the directory where I put the fmx files. And in the target field of the shortcut property I put after the ifrun60.exe the name of the fmx file which to call first.
    Now , in one of my forms file I want to get the full path of this directory because I must call Ora_Ffi.Load_Library. And the library which I want to load resides on that directory.
    So how to get programatically the directory where the fmx files reside.
    I know that there is the registry entry FORMS60_PATH, but we plan to ship many projects to that customer; so if I use the FORMS60_PATH variable then there will be an error because there will be many directories. And the customer can launch many of the projects at the same time.
    So how to get it.
    Thank you very much indeed.

    If you are using the d2kwutil library, then you can use the win_api_environment.Get_Working_Directory() function.
    If not, I doubt that there is anyway to get it since the get_application_property(current_form) does not return the full path of the form as it used to in prior versions of Oracle forms such as 4.5.

  • How to find the absolute path of file  which store in KM foler ?

    Hello everyone:
         We want to develop an ABAP program which can write files into KM folder directly.
         So I need to find the absolute path of file which store in KM folder first, then we can consider the develop solution.
         Is this issue possbile that an ABAP  program write files into KM folder  directly ?
         Is there anybody had done this job ?
    Best Regards,
    Jianguo Chen

    Hi,
    http://forum.java.sun.com/thread.jsp?forum=34&thread=36
    612The methods in the above topic seem to be available when use a DOM parser..

  • Why do Analysis VIs need the full path to lvanlys.dll?

    I've noticed that all Analysis VIs contain the full pathname of the lvanlys.dll that is being called.  This means that the .lvproj file lists this fully qualified DLL filename as a dependency of the project.  This turns out to be an issue if the same project is opened in both 32-bit and 64-bit LabVIEW - the pathname changes from "Program Files (x86)/..." to "Program Files/...", and the project has a "dirty dot".  Some other VI libraries which also call DLLs located in the resource directory do not use the full path name (for example, the Vision VIs and the Wavelet Analysis VIs are two I noticed) and their dependencies are stored in the .lvproj file with the property "NI.PreserveRelativePath" set to "true".
    Is there a reason why the full path is necessary, and if not, can it be removed?  I've also notice that VIs calling lvinput.dll and lvsound2.dll have a full pathname, but haven't tracked through to see which others also do, or do not.

    Hi,
    Licensing and toolkit development are reasons for whether the full pathname is being used or the property "NI.PreserveRelativePath" is set to "true". There isn't a way to change it. Also, most toolkits will only work in 32-bit LabVIEW. According to this KB, as of 2009, NI Vision is the only toolkit that can be used in LabVIEW 64-bit. You maybe able to solve your dirty dot issue by mass compiling. 
    Rohama K.

  • How do I get the full path and filename of the current document?

    I'm writing a format plug-in. How do I obtain the full path and filename of the current image (document) from within my plug-in? Any help would be greatly appreciated!

    I actually just figured this out. For anyone else who would like to know, check out the propetizer sample code in the photoshop sdk. It makes a "filter" plug-in that just spits out all the properties of the document you could ever want to know about. The function I used to get the full path and filename of the current document is PIGetDocumentName(). I hope this helps someone eventually...

Maybe you are looking for