添加 freem 命令

This commit is contained in:
Cheney
2024-09-02 17:37:31 +08:00
parent 2acd92086c
commit 4275120cba
7 changed files with 44 additions and 9 deletions
+8
View File
@@ -12,6 +12,7 @@ const path = require("path");
const fs = require("fs");
const {sm3} = require("sm-crypto");
const zlib = require("zlib");
const mem = require("./mem")
parser.addCmdLine("man", "打开在线帮助;", async function (){
const uConfig = await $context.get("uConfig")
@@ -113,6 +114,13 @@ parser.addCmdLine("install [module]", "安装/更新模块;", async function (cl
remote.install(cli.getParamValue("module"))
});
parser.addCmdLine("freem [level]", "释放内存", function (cli) {
let level = cli.getParamValue("level")
mem.free( level )
});
parser.addCmdLine("killport <port>", "释放端口", function (cli) {
let port = cli.getParamValue("port")
net.killport( parseInt(port, 10) );
+22
View File
@@ -0,0 +1,22 @@
const osutil = require("./util/osutil")
const shell = require("./shell")
function free(level) {
osutil.choise({
[osutil.Windows] : ( level ) => {
throw Error("暂不支持")
},
[osutil.Linux] : ( level ) => {
if ( [1,2,3].indexOf( parseInt(level,10)) === -1 ) {
level = 1
}
shell.execSync("sync")
shell.execSync(`echo ${level} > /proc/sys/vm/drop_caches`)
},
})
}
module.exports = {
free
}
+4 -4
View File
@@ -1,7 +1,7 @@
const os = require('os');
const fs = require("fs");
const Windows = 0;
const Linux = 1;
const Windows = "Windows";
const Linux = "Linux";
module.exports = {
@@ -11,11 +11,11 @@ module.exports = {
* 根据 os 不同,载入不同的方法
*/
choise : function ( cbs ) {
if (os.type() == 'Windows_NT') {
if (os.type() === 'Windows_NT') {
// windows平台
return cbs && cbs[ Windows ]
}
else if (os.type() == 'Linux') {
else if (os.type() === 'Linux') {
// Linux平台
return cbs && cbs[ Linux ]
}