qfedu-linux-advanced-level/day3/t14.c

25 lines
471 B
C
Raw Normal View History

2023-08-17 09:20:18 +08:00
#include <stdio.h>
#include <signal.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
int main()
{
pid_t pid;
pid = fork();
if (pid == 0)
{
// 子进程
printf("10 秒后子进程退出\n");
int s = alarm(10); // 第一次调用, s 返回 0
printf("alarm s is %d\n", s);
sleep(3);
s = alarm(10);
printf("alarm s is %d\n", s);
while (1)
;
}
return 0;
}