📜  Node.js process.title 属性

📅  最后修改于: 2022-05-13 01:56:37.543000             🧑  作者: Mango

Node.js process.title 属性

process.title 属性是进程模块的内置应用程序编程接口,用于获取和设置进程的标题。

句法:

process.title

返回值:该属性返回一个字符串值,指定进程的标题,当前值为'ps'。

注意:为该属性分配新值将修改当前值。不同的平台可以对进程标题的最大长度施加限制。

下面的例子说明了在 Node.js 中process.title 属性的使用:

示例 1:

// Node.js program to demonstrate the    
// process.title property
  
// Include process module
const process = require('process');
  
// Printing process.title property value
console.log("PID: " + process.pid + 
      " process title is " + process.title);

输出:

PID: 8852 process title is Command Prompt - node  title_1

示例 2:

// Node.js program to demonstrate the    
// process.title property
  
// Include process module
const process = require('process');
  
// Printing process.title property value
console.log("Before modification: PID: " + process.pid
          +" process title is " + process.title);
  
// Setting new process title value
process.title = "gekchosCustomProcess";
  
// Printing process.title value after modification
console.log("After modification: PID: " + process.pid
          + " process title is " + process.title);

输出:

Before modification: PID: 14012 process title is Command Prompt - node  title_2
After modification: PID: 14012 process title is gekchosCustomProcess

注意:上面的程序将使用node filename.js命令编译和运行。

参考: https://nodejs.org/api/process.html#process_process_title