I'm working at raspberry pi and node version is "node-v0.10.28-linux-arm-pi". I'm have run the below code.
'use strict' var util = require(‘util’); var config = require(‘./config.js’); var fs = require(‘fs’); var pidInfo = util.format('process id:%d’, process.pid); util.log(pidInfo); process.title = pidInfo; process.on('exit’, function () { var path = '/home/pi/test/message_1.txt’; fs.writeFileSync(path, new Date().toString()); }); process.on('SIGTERM’, function () { var path = '/home/pi/test/message.txt’; fs.writeFileSync(path, new Date().toString()); process.exit(0); }); //var exec = require(‘child_process’).exec; //exec(util.format('sudo shutdown -h %s’, '18:25'), function (err) { //if (err) //console.log(err); //}); process.stdin.resume();
When I call the linux command "kill process id" to kill the process,event SIGTERM and exit is triggered. But when it run code "exec(util.format('sudo shutdown -h......" Raspberry pi will shutdown directly and I'm unable to capture event SIGTERM and exit. I don't know why. May could you to help me please? Thank you.