In Node Red I can start something running using exec node..spawn mode gives correct pid... but...
I want to kill the running program via its PID. I can see the PID number in the status but nothing seems to come out of any of the 3 outputs. How can I make a note of the PID for later killing with another exec node.. rather than typiing it into the kill exec node
Also, if you have left it at the default (exec) mode it won't send anything till the exec is complete. If you select spawn mode then I think it will give some output immediately.
If this is yours to be able to change, you could get it to output the PID early in the process. I'm pretty sure Python has a library to get the PID just as I think NodeJS does.
without the & echo $! it works as before, manuallyt noting the status from the node status I can then stop the process - but adding that on the end,
the pid comes through the node status window promptly followed by rc2 - and the process is not running. Ideas?
Cant really use pidof myapp as I call Python with different arguments to do different things. Thats on example, enother is to light up another display. I wonder why the ampersand and echo fails....
Hugobox.. Dont understand how I would use the above in a node-red exec node... sorry, Surely there must be a way to use exec node and return the PID - it returns it in the status for all to see but I cant see any way to get that out without using pen and ink to copy the pid.
Otherwise if your exec node returns the PID in its status but then also displays "RC2", you could catch it via a status node and then filter the output in a function by type: if its a number then store in context as your PID, if its "RC2" do not store...
further up you said it does send the PID to status - then changes to RC2.... surely that means it's finished as you should only get the return code when it's complete ? So there should be nothing to kill ? - (And even if it does send it to status then you can surely grab it quick enough with the status node ?)
Also if it is a python process are you using -u to ensure you are getting unbuffered output ?
further up you said it does send the PID to status - then changes to RC2.... surely that means it's finished as you should only get the return code when it's complete ? So there should be nothing to kill ? - (And even if it does send it to status then you can surely grab it quick enough with the status node ?)
Also if it is a python process are you using -u to ensure you are getting unbuffered output ?
The rc2 was coming out of status indicating the process was not running – and I don’t know how to get info out of a node status message (underneath) other than to physically look at it.
The bash solution works.. inject a unique name into an inject node payload along with the stuff to run:
I called one of the exec nodes “thisone” and told the status node about it. Sending the output of the status node to a debug it said “undefined”… so I looked at the entire message and indeed, msg.status.text is “pid:10039” which is then easily split. Easier to conceptualise but actually ends to with more bits than previous solution and you need to store the PID somewhere. I’ll keep that on file thanks.