-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path13.c
74 lines (69 loc) · 1.79 KB
/
13.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
#include <sys/types.h>
#include <unistd.h>
#include <stdio.h>
#include <sys/wait.h>
#include <pwd.h>
#include <grp.h>
#include <limits.h>
int id(void)
{
gid_t a[NGROUPS_MAX];
int i;
printf("PID:%d,\n",getpid());
printf("PPID:%d,\n", getppid());
printf("PGID:%d,\n", getpgrp());
printf("UID:%d(%s),\n", getuid(), getpwuid(getuid())->pw_name);
printf("GID:%d(%s),\n",getgid(), getgrgid(getgid())->gr_name);
printf("SID:%d,\n",getsid(0));
printf("EUID:%d(%s),\n",geteuid, getpwuid(geteuid())->pw_name);
printf("EGID:%d(%s),\n",getegid, getgrgid(getegid())->gr_name);
printf("GROUPS:\n");
for (i=0;i<getgroups(NGROUPS_MAX, a);i++)
printf("%d(%s)\n",a[i],getgrgid(a[i])->gr_name);
return 0;
}
int main()
{
pid_t child_id=fork();
if (child_id<0)
{
perror("Failed to fork");
return 1;
}
if (child_id>0)
{
int result;
wait(&result);
printf("Parent process:\n");
if (id()!=0)
{
perror("Failed to id");
return 1;
}
printf("FINISH STATUS:");
if (result==0)
printf("OK");
else if (WIFEXITED)
printf("the child terminated normally, that is, by calling exit(3) or _exit(2), or by returning from main()");
if (WIFSIGNALED)
{
printf("the child process was terminated by a signal");
if (WCOREDUMP)
printf("the child produced a core dump");
}
if (WIFSTOPPED)
printf("the child process was stopped by delivery of a signal");
if (WIFCONTINUED)
printf("the child process was resumed by delivery of SIGCONT");
}
else {
printf("Child process:\n");
if (id()!=0)
{
perror("Failed to id");
return 1;
}
}
}
return 0;
}