process.setegid(id)
process.setegid()
方法设置进程的有效群组标识。
(请参阅 setegid(2)
。)id
可以作为数字 ID 或群组名称字符串传入。
如果指定了群组名,则此方法在解析关联的数字 ID 时会阻塞。
import process from 'node:process';
if (process.getegid && process.setegid) {
console.log(`Current gid: ${process.getegid()}`);
try {
process.setegid(501);
console.log(`New gid: ${process.getegid()}`);
} catch (err) {
console.log(`Failed to set gid: ${err}`);
}
}
const process = require('node:process');
if (process.getegid && process.setegid) {
console.log(`Current gid: ${process.getegid()}`);
try {
process.setegid(501);
console.log(`New gid: ${process.getegid()}`);
} catch (err) {
console.log(`Failed to set gid: ${err}`);
}
}
此功能仅适用于 POSIX 平台(即不适用于 Windows 或安卓)。
此特性在 Worker
线程中不可用。
The process.setegid()
method sets the effective group identity of the process.
(See setegid(2)
.) The id
can be passed as either a numeric ID or a group
name string. If a group name is specified, this method blocks while resolving
the associated a numeric ID.
import process from 'node:process';
if (process.getegid && process.setegid) {
console.log(`Current gid: ${process.getegid()}`);
try {
process.setegid(501);
console.log(`New gid: ${process.getegid()}`);
} catch (err) {
console.log(`Failed to set gid: ${err}`);
}
}
const process = require('node:process');
if (process.getegid && process.setegid) {
console.log(`Current gid: ${process.getegid()}`);
try {
process.setegid(501);
console.log(`New gid: ${process.getegid()}`);
} catch (err) {
console.log(`Failed to set gid: ${err}`);
}
}
This function is only available on POSIX platforms (i.e. not Windows or
Android).
This feature is not available in Worker
threads.