🆕 clock()函数

This commit is contained in:
fslongjin
2022-07-12 13:20:01 +08:00
parent 7670031b11
commit da4867d662
9 changed files with 50 additions and 9 deletions

View File

@ -432,7 +432,7 @@ int shell_cmd_exec(int argc, char **argv)
// printf("parent process wait for pid:[ %d ]\n", pid);
waitpid(pid, &retval, 0);
printf("parent process wait pid [ %d ], exit code=%d\n", pid, retval);
// printf("parent process wait pid [ %d ], exit code=%d\n", pid, retval);
free(argv);
}
}

View File

@ -27,6 +27,16 @@ int usleep(useconds_t usec)
tv_sec : (long int)(usec / 1000000),
tv_nsec : (long int)(usec % 1000000) * 1000UL
};
return nanosleep(&ts, NULL);
}
/**
* @brief 获取系统当前cpu时间
*
* @return clock_t
*/
clock_t clock()
{
return (clock_t)syscall_invoke(SYS_CLOCK, 0,0,0,0,0,0,0,0);
}

View File

@ -35,4 +35,11 @@ struct timespec
* @param rmtp 返回的剩余休眠时间
* @return int
*/
int nanosleep(const struct timespec *rqtp, struct timespec *rmtp);
int nanosleep(const struct timespec *rqtp, struct timespec *rmtp);
/**
* @brief 获取系统当前cpu时间
*
* @return clock_t
*/
clock_t clock();

View File

@ -23,6 +23,7 @@
#define SYS_EXIT 16 // 进程退出
#define SYS_MKDIR 17 // 创建文件夹
#define SYS_NANOSLEEP 18 // 纳秒级休眠
#define SYS_CLOCK 19 // 获取当前cpu时间
/**
* @brief 用户态系统调用函数