I would like to run a never-ending command (such as play a mp3 file in loop) for a period of length T.
I put the command in a shell script my.sh:
#! /bin/bash
vlc /path/to/my.mp3 # will play the file in loop till I terminate it.
and then I try to run it
my.sh &
pid="$!" # need to get the pid of the vlc process.
sleep 2.5h
kill $pid
It seems that it kills only the process running the shell script, not the process running the command in the script. How can I kill the process running the command in the script?
Thanks.