1

I'm reading through the .desktop files found in /usr/share/applications and it appears SOME don't share the same process name as the executable file (most do).

Is there a way to find that the process name will be?

Example:

Chromes .desktop file

[Desktop Entry]
Version=1.0
Name=Google Chrome
Exec=/usr/bin/google-chrome-stable %U
StartupNotify=true
Terminal=false
Icon=google-chrome
Type=Application
Categories=Network;WebBrowser;
MimeType=application/pdf;application/rdf+xml;application/rss+xml;application/xhtml+xml;application/xhtml_xml;application/xml;image/gif;image/jpeg;image/png;image/webp;text/html;text/xml;x-scheme-handler/ftp;x-scheme-handler/http;x-scheme-handler/https;
Actions=new-window;new-private-window;

When I run pidof google-chrome-stable it returns null.

But when I run pidof chrome it returns all the PID's

879321 879303 805004 755066 693852 693837 693796 688198 624316 624289 3194 2788 2762 2734 2685 2677 2641 2637 2620 2613 2611 2601

Is there a better way to find the PID?

Please note I MUST search from information found in the .desktop file. (long story)

Thanks

  • Your question is fuzzy to me. You are stating that same command returns null and a set of PIDs... – Ravexina Jun 9 at 20:42
  • Its a typo!! I've changed it – Lewis Morris Jun 9 at 20:51
1

It depends on the Exec line, it might be a shell script running another executable or it might be a link or even an executable spawning another.

I'm not sure how you can get the information only from desktop file however one solution might be to run it...

Note that I don't have google-chrome so I use chromium in my example.

# Extract the command from desktop file
$ CMD=$(grep -Po "(?<=^Exec=).+\s" /usr/share/applications/chromium.desktop)
$ echo $CMD
/usr/bin/chromium

# Run it
$ CMD &

# Get the PID
$ PID=$(echo $!)
$ echo $PID
5146

# Get process name from PID
$ ps --no-header -p $PID -o comm
chromium

# Get the complete command line + arguments
ps --no-header -p $PID -o cmd
/usr/lib/chromium/chromium --show-component-extension-options --enable-gpu-rasterization

# Terminate process
kill -SIGTERM $PID
| improve this answer | |
1

What likely happens here is that the initial executable uses an exec...() system call(*) to replace all its code by a new executable and parameters and the very same process id will correspond to that new code and be listed as such by ps, so that the initial executable disappears from the process list. This is often used to set up an environment for another executable.

(*) Or the exec builtin if it is a shell script

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.