usleep Linux: Microsecond Sleep Function
The usleep function is used in Linux to pause program execution for a specified number of microseconds, in order to create a timing effect or control the speed of the program.
The usage of the usleep function is as follows:
#include <unistd.h>
int usleep(useconds_t microseconds);
The parameter “microseconds” indicates the number of microseconds to wait, and its type is useconds_t, typically defined as an unsigned int.
After calling the usleep function, the program will pause execution for the specified number of microseconds and then continue. It is important to note that the usleep function may have some margin of error and may not be available on certain systems.
Original sentence: 我们必须采取措施来保护环境。
Paraphrased sentence: We need to take measures to protect the environment.
#include <stdio.h>
#include <unistd.h>
int main() {
printf("Start\n");
usleep(2000000); // 暂停2秒
printf("End\n");
return 0;
}
The program example above will print “Start”, pause for 2 seconds, and finally print “End”.