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

Problem Solution:

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.

Program:

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

ADVERTISEMENT
ADVERTISEMENT




Comments and Discussions!




Languages: » C » C++ » C++ STL » Java » Data Structure » C#.Net » Android » Kotlin » SQL
Web Technologies: » PHP » Python » JavaScript » CSS » Ajax » Node.js » Web programming/HTML
Solved programs: » C » C++ » DS » Java » C#
Aptitude que. & ans.: » C » C++ » Java » DBMS
Interview que. & ans.: » C » Embedded C » Java » SEO » HR
CS Subjects: » CS Basics » O.S. » Networks » DBMS » Embedded Systems » Cloud Computing
» Machine learning » CS Organizations » Linux » DOS
More: » Articles » Puzzles » News/Updates

© https://www.includehelp.com some rights reserved.