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.
/proc/PID/cmdline
and write if conditions depending on the first or second name. Like if it is python take second. If it is an executable, first one etc. – Ajay Brahmakshatriya