xxxxxxxxxx
The Difference Between kill and pkill
The kill command is a wrapper to the kill system call, which knows only about process IDs. pkill can determine the process ID based on things like, process name, owner of the process or session id.
Syntax:
$ kill 1234
$ pkill -f node
xxxxxxxxxx
pidof slack
9734 9718 9716 9708 9622 9619
sudo kill -9 process_id
pidof apt
9734 9718 9716 9708 9622 9619
sudo kill -9 9734 9718 9716 9708 9622 9619
xxxxxxxxxx
const { exec } = require('child_process');
// Execute the command to kill all Node.js processes
exec('killall node', (error, stdout, stderr) => {
if (error) {
console.error(`Error executing command: ${error}`);
return;
}
console.log(`STDOUT: ${stdout}`);
console.error(`STDERR: ${stderr}`);
});