3

I'm running two instances of omxiv (Omx Image Viewer). The first instance acts like a background image, and the second instance acts as a slideshow. My question is how can I specifically kill the second instance?

Small note: The second instance will always be opened after the first instance.

I was thinking about killing it by pid, but I am not sure if it will have the same pid after the reboot, therefore this might not work.

Right now I am calling:

pkill -9 omxiv

which is terminating both instances.

14

pkill has a -n flag that will make it only affect the most recently started ("newest") matching process.

pkill -n omxiv

If the omxiv process is well behaved, there is no need to use -9.

There is also a -o flag that will make pkill send a signal to the oldest matching process.

Note that using pkill -n will always kill the newest instance. If you have three processes, it will kill the third, not the second (as per title of question).

| improve this answer | |
  • That's exactly what I needed, it works great. Thanks for explanation – Dino Jan 13 '19 at 11:30
  • According to the man page, this also works on Debian and Ubuntu. – kasperd Jan 13 '19 at 19:52
  • 1
    @kasperd I was a bit careful, because OpenBSD pkill has some options not implemented on Linux systems, for example -q to be quiet. – Kusalananda Jan 13 '19 at 20:29

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.