ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Introduction to Linux - A Hands on Guide
This guide was created as an overview of the Linux Operating System, geared toward new users as an exploration tour and getting started guide, with exercises at the end of each chapter.
For more advanced trainees it can be a desktop reference, and a collection of the base knowledge needed to proceed with system and network administration. This book contains many real life examples derived from the author's experience as a Linux system and network administrator, trainer and consultant. They hope these examples will help you to get a better understanding of the Linux system and that you feel encouraged to try out things on your own.
Click Here to receive this Complete Guide absolutely free.
I am writing a multithreaded program using pthreads, and I'm having a problem. My program is a daemon which runs in the background and has two threads. The first thread is an infinite loop that helps with a timer function in my program. The second is a thread which uses libpcap to listen to a network interface. I want to use signal() to setup a signal handler which will properly clean up after the program, killing both threads, closing log files, etc, but I'm not sure how to do this. Currently this is what I'm doing:
Declare a global keep_going variable and set it to true
Register signal handler
Create threads 1 & 2 and wait for them to exit
Thread 1 Thread 2
while(1) pcap_loop() (essentially an infinite loop)
check for timeouts
sleep 10 seconds
The signal handler function simply closes log files, sets keep_going to 0, and calls pthread_join() on thread 1 on so that the next time the loop in thread 1 starts over, thread 1 will terminate. However, this is not ideal, because you could have to wait up to 10 seconds for thread 1 to terminate, and I don't know how to make thread 2 terminate. Does anyone have any ideas for a better way to do this?