-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
exit.c
68 lines (54 loc) · 1.4 KB
/
exit.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
#include <libc.h>
/*
What:
A new process is created. Both, the current and the new process, print a different
message to the screen with the return value of the fork syscall, but the child
process exits before printing it's message.
Expected:
The current process (parent) prints "Padre: <ret>" being ret the child's PID.
The child process does not print anything.
*/
int exit_success(void)
{
int ret = -1;
if ((ret = fork()))
{
println("Padre: ");
printvar(ret);
}
else
{
exit();
println("Hijo: ");
printvar(ret);
}
// Let enough time so that the new process starts execution and exits
delay(50);
return (ret > 0);
}
void *call_exit(void *arg)
{
int ret = false;
exit();
ret = 21;
return (void *)ret;
}
/*
What:
A new thread is created and performs the exit syscall with exit value 0. Then returns 21.
Expected:
The return value of the created thread is 21 as only the masterthread of a process can
execute the exit syscall. (The return statement will implicitly perform a pthread_exit)
*/
int exit_calling_thread_is_not_master(void)
{
int ret = -1;
int TID, retval;
ret = pthread_create(&TID, &call_exit, NULL);
if (ret < 0 || TID <= 0)
return false;
ret = pthread_join(TID, &retval);
if (ret < 0 || retval != 21)
return false;
return true;
}