Question about terminating server prog after idle time

Posted on 2005-04-23
Last Modified: 2010-04-15

I am working on a simple socket program in which a server holds a username-password database, and then clients can connect to it and check combinations.  The problem is, the server is supposed to terminate after 50 seconds of idle time (no clients connecting to it) and I am not sure how to be watching time while waiting for a connection.  I am programming in C in a Unix environment.

Question by:Tim_Heldberg
    LVL 45

    Accepted Solution

    You can use alarm() ...


    this will send a SIGALRM to your program after 50 seconds ... You will have to write a signal handler for SIGALRM .. use sigaction interface to do that

    man sigaction
    LVL 45

    Expert Comment

    Check these links

    The second link uses signal() interface ... This is outdated and now has been replaced with sigaction which is more sophisticated but the basic idea remains the same ... Also, the example there uses gets() .. avoid gets too .. read the notes/bugs section of man gets for more information.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Threat Intelligence Starter Resources

    Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

    Suggested Solutions

    An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
    Windows programmers of the C/C++ variety, how many of you realise that since Window 9x Microsoft has been lying to you about what constitutes Unicode ( They will have you believe that Unicode requires you to use…
    The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
    Video by: Grant
    The goal of this video is to provide viewers with basic examples to understand and use while-loops in the C programming language.

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now