C语言的sleep,wait,delay函数有什么区别

如题所述

wait 是等待子进程的返回sleep 参数指定暂停时间, 单位是 sdelay 参数指定暂停时间, 单位是 ms所以 sleep(n) == delay(1000*n)原型:extern void sleep(unsigned int sec);用法:#include <system.h功能:短暂延时说明:延时sec秒举例:// sleep.c#include <system.hmain(){int c;clrscr();printf("\nHello, world!");sleep(1);clrscr();printf("\nHi, guys");getchar();return 0;}原型:extern void delay(unsigned int msec);用法:#include <system.h功能:短暂延时说明:延时msec*4毫秒举例:// delay.c#include <system.hmain(){int c;clrscr();printf("\nHello, world!");delay(250); // 250*4=1000msec=1secclrscr();printf("\nHi, guys");getchar();return 0;}wait(等待子进程中断或结束)相关函数waitpid,fork表头文件#include<sys/types.h#include<sys/wait.h定义函数pid_t wait (int * status);函数说明wait()会暂时停止目前进程的执行,直到有信号来到或子进程结束。如果在调用wait()时子进程已经结束,则wait()会立即返回子进程结束状态值。子进程的结束状态值会由参数status 返回,而子进程的进程识别码也会一快返回。如果不在意结束状态值,则参数status可以设成NULL。子进程的结束状态值请参考waitpid()。返回值如果执行成功则返回子进程识别码(PID),如果有错误发生则返回-1。失败原因存于errno中。
温馨提示:答案为网友推荐,仅供参考

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网