1.获取并改变当前程序的目录
console.log("now dir is:"+process.cwd());
process.chdir('/home/shiyanlou/wangyiyun');
console.log("now dir is:"+process.cwd());
chdir 里的参数要是完整路径
2.查看系统相应信息
console.log(process.pid);
console.info();
console.log(process.title);
console.info();
console.log(process.version);
console.log(process.versions);
process.version 是版本号 process.versions是版本属性 得到一个json对象
console.log(process.config);
console.info();
console.log(process.execPath);
console.info();
console.log(process.argv);
config 是nodejs的配置信息 也是一个json对象
execPath 是当前进程的可执行文件的绝对路径
argv 得到命令行参数数组
console.log(process.platform);
console.info();
console.log(process.arch);
console.info();
console.log(process.env);
第一个打印的是平台 linux windows
第二个是cpu架构信息 x64
第三个是shell里面各种有用的环境变量的地址
process.stdout.write("字符串");标准输出流
process.stderr.write();标准错误流
process.stderr.write()标准输入流
process.kill
process.on('SIGHUP',function(){
console.log('Got SIGHUP signal.');
});
setTimeout(function(){
console.log('Exiting');
process.exit(0);
console.info("has aleady kill "+proecess.pid);
},1000);
process.kill(process.pid,'SIGHUP');
process的异步操作模块
console.time('startB');
console.log('start-setTimeout');
setTimeout(function(){
console.log('nextTick callback 2');
},0);
console.log('scheduled-setTimeout');
console.timeEnd('startB');
console.time('startA');
console.log('start-nextTick');
process.nextTick(function(){
console.log('nextTick callback 1');
});
console.log('scheduled-nextTick');
console.timeEnd('startA');
console.info();
这里面 process.nextTick()与setTimeout()一样完成了异步操作 但是前者几乎没有阻塞 效率高于后者