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。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。
