Elegant way to get pid of exec node running in spawn mode? I guess I can grab the command before I pass it into the exec node and poll its process detail while the exec node is busy? But thought there might be a better way?
Does it not provide it as a status message ?
Not that I am seeing... I solved the issue by running another exec node in parallel using 'ps' to snag the pid and cpu%, then display same while the initial exec node is running. So issue resolved. But, yes, would be nice if pid was returned as a message part when exec node is used in spawn mode. Maybe even pass in a parameter string, like what you do with 'ps -eo' such that user could get pid, command text, cpu%, memory%, etc. for the process running.
Here is the flow, it is a bit over kill, since I wanted it to 'look' nice while running, formatting output, etc.
[{"id":"8a41ccbe.25b5","type":"tab","label":"Update Monitor 1.0.0","disabled":false,"info":""},{"id":"66475d3a.7f53c4","type":"ui_button","z":"8a41ccbe.25b5","name":"Update","group":"f98ea2f.eba606","order":1,"width":2,"height":1,"passthru":false,"label":"Update","tooltip":"","color":"","bgcolor":"","icon":"","payload":"","payloadType":"str","topic":"","x":280,"y":80,"wires":[["e7128fd6.71ddc","70efba4e.1669a4","96fbebd0.c33098"]]},{"id":"a373d0c9.f0409","type":"exec","z":"8a41ccbe.25b5","command":"","addpay":true,"append":"","useSpawn":"true","timer":"","oldrc":false,"name":"Update","x":580,"y":120,"wires":[["a1473577.5c56d8"],[],["ace8c38f.0b97d"]]},{"id":"725740d.4b87ac","type":"ring-buffer","z":"8a41ccbe.25b5","name":"Buffer","capacity":"20","order":"old-to-new","sendOnlyIfFull":false,"pushAfterClear":false,"extra":false,"perTopic":false,"x":1190,"y":180,"wires":[["2d14af13.579f4"]]},{"id":"2d14af13.579f4","type":"template","z":"8a41ccbe.25b5","name":"Line","field":"payload","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"<!DOCTYPE html>\n<html>\n <head></head>\n <body>\n <ul style=\"list-style: none;\">\n {{#payload}}\n <li>{{line}}</li>\n {{/payload}}\n </ul>\n </body>\n</html>","output":"str","x":1330,"y":180,"wires":[["c64097d9.1c7308"]]},{"id":"c64097d9.1c7308","type":"ui_template","z":"8a41ccbe.25b5","group":"f98ea2f.eba606","name":"Text","order":2,"width":26,"height":9,"format":"<div ng-bind-html=\"msg.payload\"></div>","storeOutMessages":true,"fwdInMessages":true,"resendOnRefresh":true,"templateScope":"local","x":1470,"y":160,"wires":[["14bc7215.cf284e"]]},{"id":"10130bf7.7e7a34","type":"function","z":"8a41ccbe.25b5","name":"Out","func":"const theLine = msg.payload.replace('\\n','\\n\\n'),\n theLength = msg.payload.trim().length;\n\nmsg.payload = { line: theLine, length: theLength};\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":890,"y":140,"wires":[["9c42fcf8.4a7bc"]]},{"id":"23f949ec.318486","type":"inject","z":"8a41ccbe.25b5","name":"Automatic","props":[{"p":"enabled","v":"true","vt":"bool"}],"repeat":"","crontab":"","once":true,"onceDelay":0.1,"topic":"","x":110,"y":100,"wires":[["66475d3a.7f53c4","cb254008.7f0e2"]]},{"id":"7b9d7291.72b56c","type":"link in","z":"8a41ccbe.25b5","name":"","links":["272a47f9.f8af88","e9e87681.2aec18","c43d4c53.5fb3a","b2ada784.827c28","39f8a2eb.ff133e","b6c17525.412e08","df91f7bc.4d7258","a1473577.5c56d8"],"x":775,"y":140,"wires":[["10130bf7.7e7a34"]]},{"id":"fc2a3b48.a02df8","type":"exec","z":"8a41ccbe.25b5","command":"","addpay":true,"append":"","useSpawn":"true","timer":"","oldrc":false,"name":"Upgrade","x":580,"y":200,"wires":[["df91f7bc.4d7258"],[],["f7f64ad6.375988"]]},{"id":"1f96ebce.92bf54","type":"complete","z":"8a41ccbe.25b5","name":"Update","scope":["a373d0c9.f0409"],"uncaught":false,"x":270,"y":200,"wires":[["268a6ee0.9a21d2"]]},{"id":"baf9b740.5ab428","type":"complete","z":"8a41ccbe.25b5","name":"Upgrade","scope":["fc2a3b48.a02df8"],"uncaught":false,"x":280,"y":280,"wires":[["33658c73.005c64"]]},{"id":"a1473577.5c56d8","type":"link out","z":"8a41ccbe.25b5","name":"","links":["7b9d7291.72b56c","ca53f80a.5a13c8"],"x":695,"y":100,"wires":[]},{"id":"df91f7bc.4d7258","type":"link out","z":"8a41ccbe.25b5","name":"","links":["7b9d7291.72b56c","ca53f80a.5a13c8"],"x":695,"y":180,"wires":[]},{"id":"96fbebd0.c33098","type":"change","z":"8a41ccbe.25b5","name":"Update","rules":[{"t":"set","p":"command","pt":"flow","to":"sudo apt-get -y update","tot":"str"},{"t":"set","p":"payload","pt":"msg","to":"command","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":420,"y":120,"wires":[["a373d0c9.f0409"]]},{"id":"268a6ee0.9a21d2","type":"change","z":"8a41ccbe.25b5","name":"Upgrade","rules":[{"t":"set","p":"command","pt":"flow","to":"sudo apt-get -y upgrade","tot":"str"},{"t":"set","p":"payload","pt":"msg","to":"command","tot":"flow"}],"action":"","property":"","from":"","to":"","reg":false,"x":420,"y":200,"wires":[["fc2a3b48.a02df8"]]},{"id":"2ab49f36.5fcf7","type":"change","z":"8a41ccbe.25b5","name":"Clear","rules":[{"t":"set","p":"clear","pt":"msg","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":1050,"y":180,"wires":[["725740d.4b87ac"]]},{"id":"e7128fd6.71ddc","type":"link out","z":"8a41ccbe.25b5","name":"","links":["a35f9b.09afc068","c8298929.acbca8"],"x":375,"y":80,"wires":[]},{"id":"a35f9b.09afc068","type":"link in","z":"8a41ccbe.25b5","name":"","links":["e7128fd6.71ddc"],"x":935,"y":180,"wires":[["2ab49f36.5fcf7"]]},{"id":"9c42fcf8.4a7bc","type":"switch","z":"8a41ccbe.25b5","name":"Length?","property":"payload.length","propertyType":"msg","rules":[{"t":"gt","v":"0","vt":"num"}],"checkall":"true","repair":false,"outputs":1,"x":1040,"y":140,"wires":[["725740d.4b87ac"]]},{"id":"f7f64ad6.375988","type":"link out","z":"8a41ccbe.25b5","name":"","links":["e1bc723a.d31b1"],"x":695,"y":220,"wires":[]},{"id":"ace8c38f.0b97d","type":"link out","z":"8a41ccbe.25b5","name":"","links":["e1bc723a.d31b1"],"x":695,"y":140,"wires":[]},{"id":"500ea416.cff32c","type":"function","z":"8a41ccbe.25b5","name":"Result","func":"const COMMAND = 'command';\n\nvar theResult = msg.payload.code,\n theLine = `Command: '${flow.get(COMMAND)}', Result: ${theResult}`;\n\nmsg.payload = { line: theLine, result: theResult};\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":890,"y":220,"wires":[["d4ac58ca.68ffa8"]]},{"id":"e1bc723a.d31b1","type":"link in","z":"8a41ccbe.25b5","name":"","links":["f7f64ad6.375988","ace8c38f.0b97d"],"x":775,"y":220,"wires":[["500ea416.cff32c"]]},{"id":"d4ac58ca.68ffa8","type":"switch","z":"8a41ccbe.25b5","name":"Result?","property":"payload.result","propertyType":"msg","rules":[{"t":"neq","v":"0","vt":"num"}],"checkall":"true","repair":false,"outputs":1,"x":1040,"y":220,"wires":[["725740d.4b87ac"]]},{"id":"70efba4e.1669a4","type":"change","z":"8a41ccbe.25b5","name":"Disable","rules":[{"t":"set","p":"enabled","pt":"msg","to":"false","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":420,"y":40,"wires":[["c99c031b.3def4"]]},{"id":"c99c031b.3def4","type":"link out","z":"8a41ccbe.25b5","name":"","links":["5eb63953.4ed008","e18329fe.083268","ca53f80a.5a13c8"],"x":535,"y":40,"wires":[]},{"id":"5eb63953.4ed008","type":"link in","z":"8a41ccbe.25b5","name":"","links":["c99c031b.3def4","ea423086.f3deb"],"x":155,"y":60,"wires":[["66475d3a.7f53c4"]]},{"id":"33658c73.005c64","type":"change","z":"8a41ccbe.25b5","name":"Enable","rules":[{"t":"set","p":"enabled","pt":"msg","to":"true","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"x":440,"y":280,"wires":[["ea423086.f3deb"]]},{"id":"ea423086.f3deb","type":"link out","z":"8a41ccbe.25b5","name":"","links":["5eb63953.4ed008","e18329fe.083268","ca53f80a.5a13c8"],"x":555,"y":280,"wires":[]},{"id":"e18329fe.083268","type":"link in","z":"8a41ccbe.25b5","name":"","links":["c99c031b.3def4","ea423086.f3deb"],"x":775,"y":100,"wires":[["b19db041.9ac17"]]},{"id":"5b7484e.e57837c","type":"function","z":"8a41ccbe.25b5","name":"Enable Or Disable","func":"msg.payload = flow.get('buffer');\nmsg.enabled = !msg.enabled;\n\nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":1110,"y":100,"wires":[["4caba239.ec315c"]]},{"id":"14bc7215.cf284e","type":"change","z":"8a41ccbe.25b5","name":"Buffer","rules":[{"t":"set","p":"buffer","pt":"flow","to":"payload","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":1610,"y":160,"wires":[[]]},{"id":"4caba239.ec315c","type":"link out","z":"8a41ccbe.25b5","name":"","links":["8cfa47a5.1c2fd8","171a7a10.596576"],"x":1255,"y":100,"wires":[]},{"id":"8cfa47a5.1c2fd8","type":"link in","z":"8a41ccbe.25b5","name":"","links":["4caba239.ec315c"],"x":1355,"y":140,"wires":[["c64097d9.1c7308"]]},{"id":"b19db041.9ac17","type":"delay","z":"8a41ccbe.25b5","name":"Wait (250ms)","pauseType":"delay","timeout":"250","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":910,"y":100,"wires":[["5b7484e.e57837c"]]},{"id":"d60ec15.a55224","type":"ui_text","z":"8a41ccbe.25b5","group":"f98ea2f.eba606","order":3,"width":2,"height":1,"name":"Process","label":"{{msg.payload}}","format":"","layout":"row-left","x":1280,"y":320,"wires":[]},{"id":"ca126a4e.428508","type":"delay","z":"8a41ccbe.25b5","name":"Wait (500ms)","pauseType":"delay","timeout":"500","timeoutUnits":"milliseconds","rate":"1","nbRateUnits":"1","rateUnits":"second","randomFirst":"1","randomLast":"5","randomUnits":"seconds","drop":false,"x":1290,"y":360,"wires":[["55dac86b.edffd8"]]},{"id":"ca53f80a.5a13c8","type":"link in","z":"8a41ccbe.25b5","name":"","links":["cb254008.7f0e2","ea423086.f3deb","c99c031b.3def4","a1473577.5c56d8","df91f7bc.4d7258"],"x":655,"y":360,"wires":[["eea3edf4.d619b"]]},{"id":"cb254008.7f0e2","type":"link out","z":"8a41ccbe.25b5","name":"","links":["ca53f80a.5a13c8"],"x":235,"y":120,"wires":[]},{"id":"3a90e44e.2a071c","type":"exec","z":"8a41ccbe.25b5","command":"ps -eo pid,%cpu,cmd | grep 'apt-get' | grep -v sudo | grep -v grep","addpay":false,"append":"","useSpawn":"false","timer":"","oldrc":false,"name":"Get","x":990,"y":360,"wires":[["65aa710a.1e91"],[],[]]},{"id":"65aa710a.1e91","type":"function","z":"8a41ccbe.25b5","name":"Parse","func":"const PROCESS = msg.payload.trim().split(/[ ]+/),\n ID = 0,\n LOAD = 1;\n\nvar theLoad = PROCESS[LOAD];\n theId = PROCESS[ID];\n\nif (theLoad) \n msg.payload = `${theLoad}% (${theId})`;\n \nreturn msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":1130,"y":340,"wires":[["d60ec15.a55224","ca126a4e.428508"]]},{"id":"55dac86b.edffd8","type":"link out","z":"8a41ccbe.25b5","name":"","links":[],"x":1415,"y":360,"wires":[]},{"id":"171a7a10.596576","type":"link in","z":"8a41ccbe.25b5","name":"","links":["4caba239.ec315c"],"x":1015,"y":300,"wires":[["59509ef9.60fa7"]]},{"id":"59509ef9.60fa7","type":"change","z":"8a41ccbe.25b5","name":"Clear","rules":[{"t":"set","p":"payload","pt":"msg","to":"","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":1130,"y":300,"wires":[["d60ec15.a55224"]]},{"id":"eea3edf4.d619b","type":"traffic","z":"8a41ccbe.25b5","name":"Enable Or Disable","property_allow":"enabled","filter_allow":"false","ignore_case_allow":true,"negate_allow":false,"send_allow":false,"property_stop":"enabled","filter_stop":"true","ignore_case_stop":true,"negate_stop":false,"send_stop":false,"default_start":false,"differ":false,"x":810,"y":360,"wires":[["3a90e44e.2a071c"]]},{"id":"f98ea2f.eba606","type":"ui_group","z":"","name":"Tasks","tab":"871457a6.90a408","order":1,"disp":true,"width":"28","collapse":true},{"id":"871457a6.90a408","type":"ui_tab","z":"","name":"Administration","icon":"dashboard","order":10,"disabled":false,"hidden":false}]
This flow started as an idea to understand how to element scrolling text output, and kinda morphored into more as I was playing with idea.
Hmm - it should do... and be catchable by the status node.
Ah! I was looking for it... in the message returned from the exec node its self. As a message part or part of the payload. Thanks.
I still need the cpu% (load) information so I guess I will need the additional exec node anyway.
This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.