There are a bunch of system calls used to to retrieve the:
process id
parent process id
process group id
real user id
effective user id
real group id
effective group id
System Definitions:
ubuntu@ip-172-31-23-227:~$ less /usr/include/unistd.h
......
/* Get the process ID of the calling process. */
extern __pid_t getpid (void) __THROW;
/* Get the process ID of the calling process's parent. */
extern __pid_t getppid (void) __THROW;
/* Get the process group ID of the calling process. */
extern __pid_t getpgrp (void) __THROW;
......
/* Get the real user ID of the calling process. */
extern __uid_t getuid (void) __THROW;
/* Get the effective user ID of the calling process. */
extern __uid_t geteuid (void) __THROW;
/* Get the real group ID of the calling process. */
extern __gid_t getgid (void) __THROW;
/* Get the effective group ID of the calling process. */
extern __gid_t getegid (void) __THROW;
......
2. Example:
proc.c:
#include<stdio.h>
#include<stdlib.h>
#include<unistd.h>
int main(int argc, char* argv[])
{
printf("%30s:%d \n", "Process ID", getpid());
printf("%30s:%d \n", "Parent Process ID", getppid());
printf("%30s:%d \n", "Process Group ID", getpgrp());
printf("%30s:%d \n", "real user id", getuid());
printf("%30s:%d \n", "effective user id", geteuid());
printf("%30s:%d \n", "real user group id", getgid());
printf("%30s:%d \n", "effective user group id", getegid());
exit(0);
}
shell:
It indicates that current process id is 4048.
ubuntu@ip-172-31-23-227:~$ ./proc.out
Process ID:4148
Parent Process ID:4069
Process Group ID:4148
real user id:1000
effective user id:1000
real user group id:1000
effective user group id:1000
Note:
Process ID 0 is the id of scheduler process, often known as "swapper", it is part of the kernel.
Process ID 1 is the id of "init" process, and is invoked by the kernel at the end of bootstrap procedure.
No comments:
Post a Comment