qfedu-linux-advanced-level/day2/d7.c

19 lines
396 B
C
Raw Permalink Normal View History

2023-08-15 19:05:13 +08:00
#include <stdio.h>
#include <sys/types.h>
#include <unistd.h>
#include <time.h>
int main(int argc, char const *argv[])
{
time_t at = time(NULL);
char buf[32] = "";
sprintf(buf, "%d 运行中", getpid());
write(1, buf, sizeof(buf));
sleep(2);
time_t bt = time(NULL);
printf("\n%d 结束\n", getpid());
printf("运行时间:%ld 秒\n", bt - at);
return 0;
}