blob: 6b9aa15d3531d242847e5ef787531fefb71fe761 (
plain)
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
|
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <unistd.h>
#include <sys/wait.h>
int main()
{
int mem = 0, pid;
pid = fork();
if (pid == -1) {
mem = 1;
perror("fork");
exit(1);
}
if (pid == 0) {
int burn;
for (burn = 0; burn < 100000; burn++) /* burncpu */__asm__ __volatile("":::"memory") ;
if (mem == 0)
exit(0);
else
exit(1);
} else {
int ret;
int status;
while((ret = waitpid(pid, &status, 0)) != pid) {
if (errno != EINTR) {
perror("waitpid");
exit(1);
}
}
mem = status;
}
if (mem == 0)
printf("mem is zero\n");
return 0;
}
|