#include <stdio.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>
#include <time.h>
int main() {
pid_t pid;
int status;
// 记录开始时间
clock_t start = clock();
// 创建子进程
pid = fork();
if (pid < 0) {
perror("fork error");
return -1;
} else if (pid == 0) {
// 子进程
sleep(1);
return 0;
} else {
// 父进程
wait(&status);
}
// 记录结束时间
clock_t end = clock();
// 计算执行时间
double executionTime = (double)(end - start) / CLOCKS_PER_SEC;
// 比较执行时间,进行计时攻击
if (executionTime > 1.0) {
printf("System call is completed.\n");
}
return 0;
}