×

C Programs

C Basic & Conditional Programs

C Looping Programs

C String Programs

C Miscellaneous Programs

C program to demonstrate the sleep() and usleep() functions for Linux operating system

Here, we are going to demonstrate the sleep() and usleep() functions for Linux operating system in C programming language.
Submitted by Nidhi, on July 22, 2021

sleep() and usleep() Functions

Here, we will use the sleep() and usleep() functions. These functions are used to halt program execution for a specific time. The sleep() function accepts time in seconds while usleep() accepts in microseconds.

C program for sleep() and usleep() functions for Linux operating system

The source code to demonstrate sleep() and usleep() functions for the linux operating system is given below. The given program is compiled and executed using GCC compile on UBUNTU 18.04 OS successfully.

// C program to demonstrate the sleep() and usleep() functions
// for Linux operating system

#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

int main(int argc, char* argv[])
{
    printf("Sleep program for 2 seconds\n");
    sleep(1);

    printf("Sleep program for 1000000 micro seconds\n");
    usleep(1000000);

    printf("Program finished\n");

    return 0;
}

Output

Sleep program for 2 seconds
Sleep program for 1000000 micro seconds
Program finished

Explanation

In the above program, we used sleep() and usleep() function to sleep program execution for a specific time.

C Advance Programs »

Related Programs

Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.