Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Sleep a thread for an indefinite amount of time in Linux

Tags:

c

linux

I want to make a thread sleep for an indefinite amount of time. The reason I want to do this is because my program only takes action when it receives a signal and has nothing to do in the primary thread. Therefore, all processing is done inside the signal handler. How can I sleep for an indefinite amount of time?

like image 223
MetallicPriest Avatar asked Sep 01 '11 13:09

MetallicPriest


People also ask

How to make a thread sleep in Linux?

sleep() function does not cease a specific thread, but it stops the whole process for the specified amount of time. For stopping the execution of a particular thread, we can use one pthread condition object and use pthread_cond_timedwait() function for making the thread wait for a specific amount of time.

How to sleep thread in c?

The sleep() method in the C programming language allows you to wait for just a current thread for a set amount of time. The sleep() function will sleep the present executable for the time specified by the thread. Presumably, the CPU and other operations will function normally.

What is sleep return C?

The sleep function waits for seconds seconds or until a signal is delivered, whichever happens first. If sleep returns because the requested interval is over, it returns a value of zero. If it returns because of delivery of a signal, its return value is the remaining time in the sleep interval.


1 Answers

I believe you're looking for the pause function:

http://pubs.opengroup.org/onlinepubs/9699919799/functions/pause.html

You could do something like: for (;;) pause();

like image 180
R.. GitHub STOP HELPING ICE Avatar answered Sep 19 '22 22:09

R.. GitHub STOP HELPING ICE