Hello I have this command on my Nodejs application which finds a process with the trim name and kills it.
let killTrim = () => { console.log('kill "$(pgrep -f ' + trimName + '.mp4)"') cmd.run('kill "$(pgrep -f ' + trimName + '.mp4)"') trimName = null }
this works perfectly fine on localhost on my computer but won't work on my server (ubuntu 16.04). The console log is outputted but the cmd.run command doesn't run on the server. When I manually put in 'kill "$(pgrep -f moo.mp4)"' on the server it will run and kill the process.
I've done some research on the issue but I haven't been able to find anything issues similar to this.
3 Answers
Answers 1
I would use something simple like below
cmd = require('node-cmd'); cmd.get('pgrep -f node | xargs kill', (err, data, stderr) => { console.log(err, data, stderr); });
It will work even when you have multiple processes running
Answers 2
It seems to be that your node application does not have enough permission to kill the process. You can try the following:
sudo node app.js
Answers 3
I looked on your pastebin. Looks like that pgrep -f ...
return more than one pid. So try this one:
cmd.run('for a in $(pgrep -f '+trimName+'.mp4); do kill $a; done');
0 comments:
Post a Comment