Close one after one with the exec node the 2 instances of vlc displayed

When I launch the radio stream, for example, I can kill him with the SIGTERM inject node.
If I restart the radio exec node a few seconds later, and try to kill it with the SIGTERM node, it does not work.
Do you think i make a configuration error?

Ok so you can start and kill each VLC once but if you restart them, they cannot be killed the second time?

As I said, the problem is that the first kill does not kill it properly, it leaves one of the processes running. If you kill that one too then all is well. You may have to do some clever interpretting of the ps command. If you run your flow and then run
ps -axjf|grep vlc
then (I think, you need to check the details) the second column is the process id and the first is that of the parent. So you need to find the line starting with the same pid as the one given by the exec node. Then you can kill the original process via the exec node, and manually kill the other one that it has spawned.

Belay that, a much better way.
If you start the flow and get the pid that the exec node provides (say 1234) then running the command
ps --ppid 1234
gives all the processes started by that one. So you should just be able to kill that process with an explicit kill command and kill the original via the exec node ( or by pid if that is easier).

I confirm that you are right: the processes are not killed correctly because they remain visible and active in pavucontrol.
Below is the return of the command launched in the terminal.

pi@raspberrypi:~ $ ps --ppid 5531
PID TTY TIME CMD
5532 ? 00:00:06 vlc

I am confused because my wife threatens to leave me if we do not immediately go to dinner with friends who are waiting for us! Yet solving this problem is so really important for my project!
Death in the soul, I tell you "see you tomorrow". :grinning:
Thanks a lot for your help.

1 Like

Godspeed!

Which country are you living in that you are able to go to dinner with friends? There does not seem much prospect of us (in the UK) being able to that safely for some months.

Restaurants just opened here in Finland also on the 1st of June (with special conditions). Take care there in the UK!

If I use msg.kill="SIGTERM" into the exec node it seem to kill vlc completely for me.
(Rather than default SIGINT)

[{"id":"fd2c4448.f163f8","type":"inject","z":"329bc392.151d5c","name":"","topic":"","payload":"","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":130,"y":240,"wires":[["51caf49d.76fedc"]]},{"id":"51caf49d.76fedc","type":"function","z":"329bc392.151d5c","name":"","func":"\nreturn {kill:\"SIGTERM\"};","outputs":1,"noerr":0,"x":270,"y":240,"wires":[["d5fc8ee7.c76f8"]]}]

When I inject SIGTERM with the function node, the kill status is displayed under the exec node but vlc continues to play.
2 solutions seem to work: killall or deploy the flow again

[{"id":"a8f82002.3b703","type":"exec","z":"b15d43aa.8177d","command":"DISPLAY=:0 cvlc http://listen.radioking.com/radio/132073/stream/171985","addpay":false,"append":"","useSpawn":"false","timer":"","oldrc":false,"name":"VLC Radio","x":530,"y":3820,"wires":[,,]},{"id":"8617a53e.732ae8","type":"inject","z":"b15d43aa.8177d","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":160,"y":3820,"wires":[["a8f82002.3b703"]]},{"id":"300f27d9.a4ff58","type":"inject","z":"b15d43aa.8177d","name":"","topic":"","payload":"SIGTERM","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":160,"y":3860,"wires":[["2cd1f86c.c7f418"]]},{"id":"2cd1f86c.c7f418","type":"change","z":"b15d43aa.8177d","name":"","rules":[{"t":"set","p":"kill","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":330,"y":3860,"wires":[["a8f82002.3b703"]]},{"id":"b8511e1.25807e","type":"exec","z":"b15d43aa.8177d","command":"DISPLAY=:0 cvlc ","addpay":false,"append":""rtsp://mafreebox.freebox.fr/fbxtv_pub/stream?namespace=1&service=201"","useSpawn":"false","timer":"","oldrc":false,"name":"VLC TV","x":520,"y":3920,"wires":[,,]},{"id":"46189be.6fa3464","type":"inject","z":"b15d43aa.8177d","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":160,"y":3920,"wires":[["b8511e1.25807e"]]},{"id":"d39845b9.261bd8","type":"inject","z":"b15d43aa.8177d","name":"","topic":"","payload":"SIGTERM","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":160,"y":3960,"wires":[["e048846f.81feb8"]]},{"id":"e048846f.81feb8","type":"change","z":"b15d43aa.8177d","name":"","rules":[{"t":"set","p":"kill","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":310,"y":3960,"wires":[["b8511e1.25807e"]]},{"id":"2591606f.85c3d","type":"exec","z":"b15d43aa.8177d","command":"killall vlc","addpay":false,"append":"","useSpawn":"false","timer":"","oldrc":false,"name":"killall vlc","x":340,"y":3760,"wires":[,,],"info":"### --global-key-quit <ChaƮne>\n### Quitter\n### --key-quit <ChaƮne> Quitter"},{"id":"3c23518c.6813ae","type":"inject","z":"b15d43aa.8177d","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":160,"y":3760,"wires":[["2591606f.85c3d"]]},{"id":"2c5b414b.b4156e","type":"inject","z":"b15d43aa.8177d","name":"","topic":"","payload":"","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":150,"y":4040,"wires":[["58e2a1a4.4cc22"]]},{"id":"58e2a1a4.4cc22","type":"function","z":"b15d43aa.8177d","name":"","func":"\nreturn {kill:"SIGTERM"};","outputs":1,"noerr":0,"x":290,"y":4040,"wires":[["b8511e1.25807e"]]}]

Hi please edit your post and put code between 3 backticks (graves accents) on newlines...

```
like this - code in the middle
```

Otherwise (because of forum formatting), your code cannot be imported.

I am in France and it is the same as in Finland. Possible but special conditions: no physical contact and distance of one meter.

Sorry !

[{"id":"a8f82002.3b703","type":"exec","z":"b15d43aa.8177d","command":"DISPLAY=:0 cvlc http://listen.radioking.com/radio/132073/stream/171985","addpay":false,"append":"","useSpawn":"false","timer":"","oldrc":false,"name":"VLC Radio","x":530,"y":3820,"wires":[[],[],[]]},{"id":"8617a53e.732ae8","type":"inject","z":"b15d43aa.8177d","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":160,"y":3820,"wires":[["a8f82002.3b703"]]},{"id":"300f27d9.a4ff58","type":"inject","z":"b15d43aa.8177d","name":"","topic":"","payload":"SIGTERM","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":160,"y":3860,"wires":[["2cd1f86c.c7f418"]]},{"id":"2cd1f86c.c7f418","type":"change","z":"b15d43aa.8177d","name":"","rules":[{"t":"set","p":"kill","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":330,"y":3860,"wires":[["a8f82002.3b703"]]},{"id":"b8511e1.25807e","type":"exec","z":"b15d43aa.8177d","command":"DISPLAY=:0 cvlc ","addpay":false,"append":"\"rtsp://mafreebox.freebox.fr/fbxtv_pub/stream?namespace=1&service=201\"","useSpawn":"false","timer":"","oldrc":false,"name":"VLC TV","x":520,"y":3920,"wires":[[],[],[]]},{"id":"46189be.6fa3464","type":"inject","z":"b15d43aa.8177d","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":160,"y":3920,"wires":[["b8511e1.25807e"]]},{"id":"d39845b9.261bd8","type":"inject","z":"b15d43aa.8177d","name":"","topic":"","payload":"SIGTERM","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":160,"y":3960,"wires":[["e048846f.81feb8"]]},{"id":"e048846f.81feb8","type":"change","z":"b15d43aa.8177d","name":"","rules":[{"t":"set","p":"kill","pt":"msg","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":310,"y":3960,"wires":[["b8511e1.25807e"]]},{"id":"2591606f.85c3d","type":"exec","z":"b15d43aa.8177d","command":"killall vlc","addpay":false,"append":"","useSpawn":"false","timer":"","oldrc":false,"name":"killall vlc","x":340,"y":3760,"wires":[[],[],[]],"info":"###       --global-key-quit <ChaƮne>\n###                                  Quitter\n###       --key-quit <ChaƮne>       Quitter"},{"id":"3c23518c.6813ae","type":"inject","z":"b15d43aa.8177d","name":"","topic":"","payload":"","payloadType":"date","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":160,"y":3760,"wires":[["2591606f.85c3d"]]},{"id":"2c5b414b.b4156e","type":"inject","z":"b15d43aa.8177d","name":"","topic":"","payload":"","payloadType":"str","repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":150,"y":4040,"wires":[["58e2a1a4.4cc22"]]},{"id":"58e2a1a4.4cc22","type":"function","z":"b15d43aa.8177d","name":"","func":"\nreturn {kill:\"SIGTERM\"};","outputs":1,"noerr":0,"x":290,"y":4040,"wires":[["b8511e1.25807e"]]}]

if you have the pid you could try using the negative of it to kill the process and all itā€™s childs as the spawned sub processes of the original should be in that group.
Its a known issue that has to do with the way that node.js spawn and exec work that the kill command sometimes for some processes doesnā€™t kill the childs of the spawned process.
So your kill command could look like this:
kill -TERM -1234 where 1234 is your pid.
Maybe worth a try.

I use the solution given in one of your posts to get the pid.
I will tried this code tonight.
Thanks a lot !
Laurent

Also maybe try other vlc options... - If I use vlc -I rc http://.... (rather than cvlc) then it doesn't spawn another process and so can be killed...

Of course if you then used the node-red-node-daemon node (that gives you stdin pipe to the process) you can then actually send commands and control it in other ways also....

[{"id":"8f292642.280d98","type":"inject","z":"d1e29928.8fa058","name":"start","props":[{"p":"start","v":"true","vt":"bool"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"x":170,"y":540,"wires":[["bd1b718c.90b99"]]},{"id":"bd1b718c.90b99","type":"daemon","z":"d1e29928.8fa058","name":"","command":"/usr/bin/vlc","args":"-I rc http://listen.radioking.com/radio/132073/stream/171985","autorun":false,"cr":true,"redo":false,"op":"string","closer":"SIGKILL","x":390,"y":540,"wires":[["80960f3.32ff2f"],["80960f3.32ff2f"],["80960f3.32ff2f"]]},{"id":"80960f3.32ff2f","type":"debug","z":"d1e29928.8fa058","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":890,"y":540,"wires":[]},{"id":"9722efa6.87599","type":"inject","z":"d1e29928.8fa058","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"payload":"quit","payloadType":"str","x":170,"y":580,"wires":[["bd1b718c.90b99"]]},{"id":"e1a349ea.763508","type":"inject","z":"d1e29928.8fa058","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"payload":"info","payloadType":"str","x":170,"y":620,"wires":[["bd1b718c.90b99"]]},{"id":"d8b9b9b0.7611c8","type":"inject","z":"d1e29928.8fa058","name":"","props":[{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"payload":"stats","payloadType":"str","x":170,"y":660,"wires":[["bd1b718c.90b99"]]}]
1 Like

Very, very interesting.
I will try it tonight, thanks a lot !
Laurent

Thank you all so much for your help. I have tested both approaches and they both work perfectly.
I don't know about the daemon node, but I'm going to dig this way, too.
Thanks to your help newbies like me can progress!
Laurent

3 Likes

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.