Time Limitation

I want my opengl program to run only within a certain time limit…only for a couple of seconds. Whatever the user can do is limited within this time.
How do i achieve this ?

Use a timer.
This has nothing to do with openGL.