0

Forgot to mention, running on Suse Tumbleweed, Desktop is KDE Plasma.

I have in my bin directory a symbolic link to mpv,

$ ls -l bin/Play 
lrwxrwxrwx 1 boffi users 12 Feb 11 12:33 bin/Play -> /usr/bin/mpv

and I have a script that calls Play to, ehm, play a random music file

$ cat bin/play_alarm 
#! /usr/bin/bash

files=($(find $HOME/Music/$1 -type f))
n_files=${#files[@]}
index=$(($RANDOM%$n_files))
file=${files[$index]}
body=$(
  echo $file | sed -E '
    s./home/boffi/Music/..
    s./[01][0-9]_./.
    s/\..*$//
    s./. → .g
    s._. .g
    s| → ([^→]+)$| → <b>\1</b>|')
notify-send -u low -a "The Alarm Player" --expire-time=10000 Playing "$body" &
Play --no-video --no-terminal ${files[$index]} 

In my understanding, I could kill mpv, that specific issue of mpv, using the name Play, but

$ bin/play_alarm & sleep 10 ; killall Play ; sleep 2 ; killall mpv
[1] 1385
Play: no process found
$ Terminated

[1]+  Exit 143                bin/play_alarm
$ 

My problem is "How can I change the name an executable presents itself to the system". Of course I'm doing something wrong, or I have a serious misunderstanding.

Addendum Before you ask, if I start play_alarm from the command line I can kill it using killall play_alarm but tipically play_alarm is started by a Plasma desklet, and then

  1. killall play_alarm does not work,
  2. killall Play does not work,
  3. killall mpv kills the alarm and every mpv issue that is running.

PS Should you suggest saving PIDs in temporary files, I'd prefer not to, but if everything else fails...

8
  • So, constructive feedback: you clearly need to find a better way than killall if you need something to stop that potentially runs in parallel on your computer, and any answer to your question won't change that.
    – sina bala
    Feb 11 at 12:25
  • I think a hardlink would do it. Feb 11 at 13:19
  • Note that I just tried this: ln -s /usr/bin/sleep mysleep; ./mysleep 1000 &, then, killall sleep does not kill mysleep, but killall mysleep does. So, the opposite of what you are describing! And that is well-reflected in /proc/{PID of mysleep as started above/cmdline and in […]/stat, which are the two files that killall consults for every process to decide whether to kill it. Feb 11 at 13:52
  • What I'm wondering here, is if mpv does something odd and overwrites the name it was originally given, or if running that as a desklet does something odd. What does ps show for the processes in each case? Actually, I think killall and pgrep (without -f) look at the name field in the first line of /proc/PID/status (which isn't what ps shows if you do e.g. (exec -a lion /bin/cat))
    – ilkkachu
    Feb 11 at 15:58
  • @ilkkachu You're RIGHT, it's mpv that changes back its name to mpv. I'll try to open an issue, maybe.
    – gboffi
    Feb 12 at 15:29

2 Answers 2

0

I tried with sleep and have the following observation:

ln -s /usr/bin/sleep  slapen
./slapen 900 &

ps -ef | grep slapen then gives:

ljm      2623965 2534378  0 16:53 pts/5    00:00:00 ./slapen 900
ljm      2623968 2534378  0 16:54 pts/5    00:00:00 grep slapen

The name of the process is therefore slapen instead of sleep as you suggest.

pkill slapen

gives:

[1]+  Terminated              ./slapen 900

which is what you seem to need.

-1

To clarify my comments under my question,

$ ls -l ~/bin/Play
lrwxrwxrwx 1 boffi users 12 Feb 11 12:33 /home/boffi/bin/Play -> /usr/bin/mpv
$ Play --no-terminal Music/Aldous_Harding/Party/06_Horizon.opus & sleep 3 ; ps
[1] 16098
  PID TTY          TIME CMD
11599 pts/4    00:00:00 bash
16098 pts/4    00:00:00 mpv
16121 pts/4    00:00:00 ps
$ 

On the other hand

$ ls ~/bin/mysleep /home/boffi/bin/mysleep
$ mysleep 10 & ps 
[1] 22546
  PID TTY          TIME CMD
11599 pts/4    00:00:00 bash
22546 pts/4    00:00:00 mysleep
22547 pts/4    00:00:00 ps
$ 

so that we may conclude that for some reason, or even without any reason, mpv changes back its name to mpv.

2
  • When you're adding information, please edit your question instead of putting it in an answer. It is also interesting that the ls of mysleep dir not return anything. If user accounts are set up in the usual fashion I would expect ~/bin and /home/boffi/bin to point to the same directory.
    – doneal24
    Feb 12 at 16:28
  • @doneal24 IMO the info I've posted here answers my question: I cannot do what I want to do (that is what I've done for 30+ years with other programs) because Mpv won't cooperate. If you disagree, please flag my answer.
    – gboffi
    Feb 12 at 18:54

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .