當前位置: 首頁>>代碼示例 >>用法及示例精選 >>正文


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



相關用法


注:本文由純淨天空篩選整理自anwesha0107大神的英文原創作品 Node.js | process.title Property。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。