process.setgroups()方法是過程模塊的內置應用程序編程接口,用於設置補充組ID。
用法:
process.setgroups( groups )
參數:該方法接受上麵提到和下麵描述的單個參數。
- groups:這是必填參數,字符串或整數數組或兩者均表示組ID或組名或兩者。
 
返回:它不會返回任何東西。對於設置組ID,Node.js進程需要root權限,因為它是特權操作。
注意:此函數僅在POSIX平台上有效。在Windows或Android平台上不可用,因此會導致錯誤,即TypeError,setgroups不是函數。
以下示例說明了Node.js中process.setgroups()方法的使用:
範例1:
// Allocating process module 
const process = require('process'); 
  
// Printing the supplementary group 
// IDs before setting. 
console.log(process.getgroups()); 
  
// Array of Group Ids 
var arr=new Array(300, 400, 2000); 
  
// Setting the supplementary group IDs. 
process.setgroups(arr); 
  
// Printing the supplementary group IDs. 
console.log(process.getgroups());輸出:
[ 0 ] [ 300, 400, 2000, 0 ]
範例2:
// Allocating process module 
const process = require('process'); 
  
if (process.setgroups) { 
    var arr=new Array(300, 400, 2000); 
  
    // Setting the supplementary group IDs. 
    process.setgroups(arr); 
} 
  
// Checking whether the method exists or not 
if (process.getgroups) { 
  
    // Printing getgroups() 
  console.log("The supplementary group IDs:", 
           process.getgroups()); 
}輸出:
The supplementary group IDs:[ 300, 400, 2000, 0 ]
注意:僅在POSIX平台上,以上程序將使用node filename.js命令編譯並運行。
參考: https://nodejs.org/api/process.html#process_process_setgroups_groups
相關用法
- Node.js GM quality()用法及代碼示例
 - Node.js GM resize()用法及代碼示例
 - Node.js GM chop()用法及代碼示例
 - Node.js GM drawPolyline()用法及代碼示例
 - Node.js GM raise()用法及代碼示例
 - Node.js GM paint()用法及代碼示例
 - Node.js GM flop()用法及代碼示例
 - Node.js GM segment()用法及代碼示例
 - Node.js GM drawArc()用法及代碼示例
 
注:本文由純淨天空篩選整理自gekcho大神的英文原創作品 Node.js | process.setgroups() Method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。
