I am working on linux.
Is there any way to get the user defined program name, given the PID of that running program?
I want to output the program name, not the process name.
For example: I have a
java application, named as stackoverflow.java. Now the process name will be decided by the system which can be different but the program name is stackoverflow.java. So the output should be the program name, given only the PID of that running program.
There are some commands which are fulfilling partial needs like:
cat /proc/"PID"/cmdline ->
This will give the command line arguments that creates that process with given "PID". But if we have various programs in different programming languages then the format of the command which runs that program will not be same. So in that case, how to extract the exact program name from this command?
readlink -f /proc/"PID"/exe -> This will give the executable file name related to the process with given "PID". But some processes do not have executable files. In that case, it will not return anything.
Actually I am working on very large scale. I want to find the application name (or source file name or program name) for all the processes that are running on the server. So I don't want to hard code anything specifically for any programming language like java, cpp, python etc. Please suggest me something generic in this regard.