[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now


Question about terminating server prog after idle time

Posted on 2005-04-23
Medium Priority
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
  • 2
LVL 45

Accepted Solution

sunnycoder earned 750 total points
ID: 13852307
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

ID: 13852320
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.

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
The goal of this video is to provide viewers with basic examples to understand opening and writing to files in the C programming language.
The goal of this video is to provide viewers with basic examples to understand opening and reading files in the C programming language.
Suggested Courses
Course of the Month19 days, 22 hours left to enroll

872 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