process.setgid()方法是流程模塊的內置應用程序編程接口,用於設置Node.js流程的組標識。
用法:
process.setgid(id)
參數:此方法接受上述和以下描述的單個參數:
- id:它是一個必需參數,它包含一個String或一個整數,表示組名或ID,如果傳遞了組名,則在解析關聯的數字ID時會阻塞。
返回:它不返回任何值。
注意:此函數僅在POSIX平台上有效。在Windows或Android平台上不可用,因此會導致錯誤,即TypeError,setgid不是函數。
以下示例說明了Node.js中process.setgid()方法的使用:
範例1:
// Node.js program to demonstrate the
// process.setgid() Method
// Including process module
const process = require('process');
// Printing the group identity of
// the Node.js process that checks
// whether the methods exists or not
if (process.getgid && process.setgid ) {
// Setting gid
process.setgid(400);
// Printing getgid() value
console.log("The group identity of the Node.js"
+ " process:", process.getgid());
}
輸出:
The group identity of the Node.js process:400
範例2:
// Node.js program to demonstrate the
// process.setgid() Method
// Including process module
const process = require('process');
// Set gid and check whether the
// method exists or not
if (process.setgid) {
// Within try catch
try {
process.setgid(696);
console.log("gid has successfully been set");
} catch (err) {
console.log("Failed to set gid:", err);
}
}
// Check whether the method exists or not
if (process.getgid) {
// Printing getgid() calue
console.log("The group identity of the Node.js"
+ " process:", process.getgid());
}
輸出:
gid has successfully been set The group identity of the Node.js process:696
注意:上麵的程序將通過使用node filename.js
命令。
參考: https://nodejs.org/api/process.html#process_process_setgid_id
相關用法
- Node.js GM blur()用法及代碼示例
- Node.js GM drawRectangle()用法及代碼示例
- Node.js GM sharpen()用法及代碼示例
- Node.js GM drawPolyline()用法及代碼示例
- Node.js GM drawEllipse()用法及代碼示例
- Node.js GM drawCircle()用法及代碼示例
- Node.js GM drawPolygon()用法及代碼示例
注:本文由純淨天空篩選整理自gekcho大神的英文原創作品 Node.js | process.setgid() Method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。