process.setgid(id)
process.setgid()
方法为进程设置组标识。(参见 setgid(2)
)。
id
可以传入数字 ID 或组名字符串。
如果指定了组名,则此方法在解析关联的数字 ID 时会阻塞。
if (process.getgid && process.setgid) {
console.log(`当前的 gid: ${process.getgid()}`);
try {
process.setgid(501);
console.log(`新的 gid: ${process.getgid()}`);
} catch (err) {
console.log(`无法设置 gid: ${err}`);
}
}
这个函数只在 POSIX 平台有效(在 Windows 或 Android 平台无效)。
此特性在 Worker
线程中不可用。
The process.setgid()
method sets the group identity of the process. (See
setgid(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 numeric ID.
if (process.getgid && process.setgid) {
console.log(`Current gid: ${process.getgid()}`);
try {
process.setgid(501);
console.log(`New gid: ${process.getgid()}`);
} 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.