How to make a thread run for a while and sleep for a while and make it run again in a loop?

i need a thread to run for a given amount of time and make it sleep for some time and it has to run again for sometime…amount of time to run should be given by user…can anyone please explain how to implement…

Here’s a simple method.
You can optimize it more as per your requirement.

while (1)
{
        time_t end_time = time() + SECONDS_TO_RUN;
        do 
        {
                /** Work to Do **/
        } while ( time() < end_time );

        sleep( SECONDS_TO_SLEEP );
}

maybe you should have a look at the alarm() syscall. hope it helps.