-1

I run this command "httpd -d ./inst2 -k start" to boot Apache Server, and I can see this command line through "ps -ef | grep httpd". My question is if i don't know the absolute path, is there a way to get the absolute path of "./inst2"?

Thanks

Zoe
  • 27,060
  • 21
  • 118
  • 148
sudo
  • 69
  • 9
  • Stack Overflow is a site for programming and development questions. This question appears to be off-topic because it is not about programming or development. See [What topics can I ask about here](http://stackoverflow.com/help/on-topic) in the Help Center. Perhaps [Super User](http://superuser.com/) or [Unix & Linux Stack Exchange](http://unix.stackexchange.com/) would be a better place to ask. – jww Sep 30 '17 at 14:26

2 Answers2

0

You can try to GUESS what the absolute path is by examining the pseudo symbolic link /proc/PID/cwd where PID can be determined from the ps output: ls -l /proc/PID/cwd. But please note that it is just the current working directory and your path may be resolved against any other directory, so it is just a guess.

Another option, if your program opens some files using this relative path and in fact you need to determine the full path of such files, you can enumerate files currently open by some process using /proc/PID/fd pseudo directory: ls -l /proc/PID/fd. But, of course, the file can already be closed by the time of executing ls. And I don't know what it will show if the open file was moved to some other place.

  • Thank you , i tried that, but it just display "/", however, this is not related to relative path "./inst2" – sudo Oct 01 '17 at 04:18
  • i did some research, and i think /proc/pid/environ can do that, you can locate "PWD=xxx" section in that file – sudo Oct 02 '17 at 23:59
  • @sudo AFAIK `/proc/pid/environ` lists the environment variables of a process. I fear, `PWD` here is just some variable set by `bash` or other shell at the time when the process was started. But, at least, it is another way to guess. – Anatoly Trosinenko Oct 03 '17 at 11:19
  • can you give a sample to the sentence "But please note that it is just the current working directory and your path may be resolved against any other directory, so it is just a guess." In which case, it can be some other unrelated directory? – sudo Oct 03 '17 at 16:43
  • @sudo It is **current** working directory, so relative path in question could be resolved against another directory that **was current** previously. Another option, some path can be manually resolved (not using regular `open`, `stat`, etc. syscalls) against, for example, installation directory, but hope it will be stated explicitly in the docs on that program:) – Anatoly Trosinenko Oct 03 '17 at 17:25
  • 1
    see the PWD I mentioned in /proc/pid/environ can be used to locate the absolute path of "./inst2" because it's written when that cmdline is executed. So i think it's reliable – sudo Oct 03 '17 at 22:20
  • Supposing it was bash who launched the httpd and who set the PWD, this path looks very likely. – Anatoly Trosinenko Oct 04 '17 at 06:42
  • Yes, "./inst2" is actually relative to the working directory when booting the server from bash. In addition, this is applicable to RHEL-like system and regular Apache – sudo Oct 04 '17 at 22:11
-1

To get the absolute path of a file/directory even you can execute following command on linux.

  1. find $HOME -type f -name "inst2" (for file)
  2. find $HOME -type d -name "inst2" (for directory)

this can give you absolute path for any file or directory. If the file is not in your home then use sudo in front of commands and replace $HOME by /.

  • Hi thanks for that, however, this is not an efficient and reliable solution – sudo Oct 01 '17 at 04:19
  • I did some research, and i think /proc/pid/environ can do that, you can locate "PWD=xxx" section in that file – sudo Oct 02 '17 at 23:59