GETPID(2)

NAME
getpid, getuid, getgid, getgid, geteuid, getegid, getppid, getpgrp, setpgid, setuid, setgid, setsid, setreuid, setregid. - get and set process ownership information.

SYNOPSIS
#include<unistd.h>
int getpid(void);
int getuid(void);
int geteuid(void);
int getgid(void);
int getegid(void);
int getppid(void);
pid_t getpgrp(void);
int setpgid(pid_t pid,pid_t pgid);
int setreuid (uid_t ruid, uid_t euid);
int setregid (uid_t rgid, uid_t egid);
int setuid(uid_t uid);
int setgid(gid_t gid);
pid_t setsid(void);

DESCRIPTION
getpid(), getpgrp() get pid / process group.

getuid(), geteuid(), getgid(), getegid() get real and effective u/g id's.

getppid() get parent process id

setpgid() set process group to pgid for pid.

If either pid or pgid is 0, then the current value is assumed.

Process groups may only be changed under the following conditions :
1. The task must be the leader of its session.
2. The current session of the task calling setpgid() must be the session of pid. Or pgid may = pid.

setreuid(), setregid() set real and effective uid / gid, set effective uid / gid. T hese are 100% BSD compatable functions. The effect is, if any of ruid, rgid, euid, egid then the real or effective g/u id is set to that value. The restrictions on this are that normal users may swap effective and real id's, and the super user may do anything.

setuid(), setgid() sets effective AND real uid / gid. These are 100% SYSV / POSIX compatable functions. Note that once id is changed, since real and effective (or saved and effective in POSIX terminology) there is no way to become privileged again. 0 is returned on success, a negative value on error.

setsid() sets session id. This is only executable by the session leader or by the super user. session id is set to pgrp which was set to pid, the process becomes the leader of its session, and the controlling tty is set to -1. The new pgrp is returned on success, a negative value on error.

ERRORS
-EINVAL is returned if an invalid pid, pgid, etc is passed to a function.

-EPERM is returned if the permissions do not allow the requested action. Generally, the super user is the only person allowed to do anything, where as normal users may only change things to their own group / user ids.

-ESRCH is returned if the selected pid could not be found in the proc table.

FILES
linux/kernel/sched.c
linux/kernel/sys.c
/usr/include/linux/sys.h
/usr/include/unistd.h

SEEALSO
setpgrp(3)