改变进程优先级,Nodejs的os.setPriority()方法

改变进程优先级,Nodejs的os.setPriority()方法

os.setPriority()方法是os模块的内置应用程序编程接口,在nodejs v10.10之后的版本中有效,用于设置pid和优先级指定的进程的调度优先级。

语法:

os.setPriority(pid,优先级)

参数:此方法有两个参数,如上所述,如下所述:

pid:这是一个可选参数。它指定要设置其调度优先级的进程id。它的默认值是0。
priority:这是一个必需的参数。它指定了为指定进程 ID 的进程设置的优先级。此参数的值必须在 -20(最高)到 19(最低)之间。

注:-20是最高优先级,19是最低优先级。

返回值:此方法不返回任何值。

注意:由于Windows系统中的优先级与UNIX系统不同,Windows系统中的优先级映射为os.constants.priority中的六个优先级常量之一。因此,在检索值时可能与实际值略有不同。在Windows系统中,设置最高优先级需要提升用户权限。因此,有时PRIORITY_HIGHEST可能会在没有任何警告的情况下更改为PRIORITY_HIGH。

以下示例说明了在Node.js中使用os.setPriority()方法:

// Node.js program to demonstrate the    
// os.setPriority() Method
 
// Allocating os module
const os = require('os');
try{
    console.log(process.pid);
		os.setPriority(19);
		// Printing priority of current process
    console.log(os.getPriority());
}catch(err){
    // Printing error message
    console.log(": error occurred"+err);
}

改变进程优先级,Nodejs的os.setPriority()方法_第1张图片如果不想他人窥探实现原理,可对上述代码中核心的三行进行JS混淆加密。

console.log(process.pid);

os.setPriority(19);

console.log(os.getPriority());

这三行JS代码,用JShaman混淆加密之后会成为:

改变进程优先级,Nodejs的os.setPriority()方法_第2张图片这时整体代码可变成:

// Node.js program to demonstrate the    
// os.setPriority() Method
 
// Allocating os module
const os = require('os');
try{
(function(_0x25ee90,_0x417a1f){function _0x42c3b7(_0x275757,_0x4b8cbe,_0x290c1a,_0x386994,_0x338865){return _0x3c30(_0x4b8cbe-0x19a,_0x275757);}function _0x2acb1e(_0x2a389b,_0x18fdb6,_0x3b02fd,_0x473c99,_0x3ee907){return _0x3c30(_0x2a389b-0x20c,_0x3b02fd);}var _0x3c3f3f=_0x25ee90();function _0x551fbf(_0x3a0b39,_0x405d83,_0x286daf,_0x1d8884,_0xfd941f){return _0x3c30(_0x1d8884-0x25e,_0x3a0b39);}function _0x27f943(_0x5712d7,_0x41f6ab,_0x502b13,_0xff34ac,_0x17b39e){return _0x3c30(_0xff34ac-0x250,_0x502b13);}function _0x185740(_0x11a490,_0x31968c,_0x1beddb,_0x2c039a,_0x5caf23){return _0x3c30(_0x2c039a- -0x37f,_0x5caf23);}while(!![]){try{var _0x5b29ad=parseInt(_0x551fbf(0x270,0x270,0x26a,0x26a,0x26d))/0x1*(parseInt(_0x2acb1e(0x20f,0x20e,0x20f,0x211,0x216))/0x2)+-parseInt(_0x27f943(0x25f,0x25d,0x25b,0x25a,0x254))/0x3*(parseInt(_0x185740(-0x376,-0x379,-0x373,-0x379,-0x37e))/0x4)+parseInt(_0x27f943(0x24b,0x256,0x249,0x250,0x250))/0x5*(-parseInt(_0x27f943(0x252,0x25e,0x258,0x259,0x25e))/0x6)+-parseInt(_0x42c3b7(0x1a3,0x1a1,0x1a6,0x19f,0x19f))/0x7+-parseInt(_0x185740(-0x374,-0x372,-0x378,-0x372,-0x375))/0x8*(-parseInt(_0x2acb1e(0x211,0x216,0x212,0x214,0x20e))/0x9)+parseInt(_0x2acb1e(0x214,0x216,0x219,0x21c,0x216))/0xa+parseInt(_0x27f943(0x258,0x254,0x25a,0x25b,0x25d))/0xb;if(_0x5b29ad===_0x417a1f){break;}else{_0x3c3f3f["\u0070\u0075\u0073\u0068"](_0x3c3f3f["\u0073\u0068\u0069\u0066\u0074"]());}}catch(_0x57abf2){_0x3c3f3f["\u0070\u0075\u0073\u0068"](_0x3c3f3f["\u0073\u0068\u0069\u0066\u0074"]());}}})(_0x54d7,0x31226);console["\u006c\u006f\u0067"](process["\u0070\u0069\u0064"]);function _0x54d7(){var _0x3b0a3f=["dhlvVB65".split("").reverse().join(""),"ytiroirPtes".split("").reverse().join(""),"vmUdKW54012".split("").reverse().join(""),"ytiroirPteg".split("").reverse().join(""),"gol".split("").reverse().join(""),"RamddO2".split("").reverse().join(""),"dip".split("").reverse().join(""),'68049ZIGKxZ',"XjoQMA4".split("").reverse().join(""),'1663907ddfYLQ',"QNSHCH0749183".split("").reverse().join(""),"ZRSwpf654".split("").reverse().join(""),"\u0036\u0037\u0032\u0030\u0036\u0036\u006f\u0077\u006a\u0043\u0079\u004d","\u0035\u0032\u0032\u0033\u0032\u0039\u0035\u0069\u0059\u0075\u0072\u0045\u0079","BTtixW24137".split("").reverse().join("")];_0x54d7=function(){return _0x3b0a3f;};return _0x54d7();}os["\u0073\u0065\u0074\u0050\u0072\u0069\u006f\u0072\u0069\u0074\u0079"](0xc3257^0xc3244);function _0x3c30(_0x3db000,_0x54d71d){var _0x3c3065=_0x54d7();_0x3c30=function(_0x1a507f,_0x40eb3b){_0x1a507f=_0x1a507f-0x0;var _0x5baa18=_0x3c3065[_0x1a507f];return _0x5baa18;};return _0x3c30(_0x3db000,_0x54d71d);}console['log'](os['getPriority']());
}catch(err){
    // Printing error message
    console.log(": error occurred"+err);
}

你可能感兴趣的:(nodejs,进程优先级)