Skip to content

Commit

Permalink
fix(cpu): use string type in cp.exec #84
Browse files Browse the repository at this point in the history
  • Loading branch information
huangyoukun committed May 30, 2018
1 parent 4186776 commit 21eda71
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions bin/tsw/util/cpu.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,10 +132,11 @@ this.taskset = function(oriCpu, pid) {

// 打印shell执行信息
cp.exec(`taskset -cp ${pid}`, {
encoding: 'utf8',
timeout: 5000
}, function(err, data, errData) {

const str = data.toString('UTF-8');
const str = data;
const tmp = str.split(':');
let cpus;

Expand All @@ -156,12 +157,12 @@ this.taskset = function(oriCpu, pid) {
logger.error(err.stack);
}

if (data.length) {
logger.info('\n' + data.toString('UTF-8'));
if (data) {
logger.info('\n' + data);
}

if (errData.length) {
logger.error('\n' + errData.toString('UTF-8'));
if (errData) {
logger.error('\n' + errData);
}

logger.info('taskset -cp ${cpu} ${pid}', {
Expand All @@ -170,18 +171,19 @@ this.taskset = function(oriCpu, pid) {
});

cp.exec(`taskset -cp ${cpu} ${pid}`, {
encoding: 'utf8',
timeout: 5000
}, function(err, data, errData) {
if (err) {
logger.error(err.stack);
}

if (data.length) {
logger.info('\n' + data.toString('UTF-8'));
if (data) {
logger.info('\n' + data);
}

if (errData.length) {
logger.error('\n' + errData.toString('UTF-8'));
if (errData) {
logger.error('\n' + errData);
}
});

Expand Down

0 comments on commit 21eda71

Please sign in to comment.