woj-sandbox/test.c

42 lines
811 B
C
Raw Normal View History

2022-10-02 14:09:25 +08:00
#include "utils/log.h"
2022-10-02 16:06:27 +08:00
#include <stdlib.h>
2022-10-02 14:09:25 +08:00
int main() {
2022-10-02 16:06:27 +08:00
LOG_INFO("Testing Memory Limit");
void *p = malloc(sizeof(int) * 1024 * 1024 * 10);
if (!p) {
LOG_ERR("malloc failed");
}
2022-10-02 14:09:25 +08:00
2022-10-02 16:06:27 +08:00
LOG_INFO("Testing NPROC Limit");
pid_t pid = fork();
if (pid == -1) {
perror("fork failed");
} else if (pid == 0) {
2022-10-09 00:06:07 +08:00
LOG_WARN("Child process");
LOG_WARN("Exiting...");
2022-10-02 16:06:27 +08:00
exit(0);
} else {
LOG_INFO("Parent process");
}
LOG_INFO("Testing Time Limit 1");
sleep(5);
LOG_INFO("Testing Time Limit 2");
for (volatile int i = 0; i != -1; i++)
;
LOG_INFO("Exiting...");
2022-10-09 00:06:07 +08:00
// destroy stdin, stdout, stderr
close(0);
close(1);
close(2);
stdin = NULL;
stdout = NULL;
stderr = NULL;
2022-10-02 14:09:25 +08:00
return 0;
}