Killing a thread having a listener socket


 
Thread Tools Search this Thread
Operating Systems Solaris Killing a thread having a listener socket
# 1  
Old 04-13-2010
Killing a thread having a listener socket

Hi All

I have a separate thread ListenerThread having a socket listening to info broadcasted by some remote server. This is created in my main thread.

Because of requirements, once the separate thread is started I need to avoid any blocking function on the main thread. Once it comes to the point to exit the application I cannot perform a join on the listener thread so the only thing I can do is to KILL it.

My questions are:

what happens to the network resoruces allocated by the function passed to the thead? Is the socket closed properly or there might be something pending? ( most worried about this )

is this procedure fast enough i.e. is the thread killed so that interrupt immediately ?

I am working with Linux ...what command or what can I check to ensure that there is no networking resource left pending or that something went wrong for the Operating system? whatever might be pending...

I am a bit scared that the killing of the application is not fast enough to guarantee that the exit of the application is clear.

I thank you very much for your help

Regards MNSTN

NOTE: I am using boost::thread in C++
# 2  
Old 04-14-2010
A socket is a file descriptor. All file descriptors have an implicit close() performed on them during image rundown. When you close a listener socket fd the port will likely go into TIMED_WAIT state.

If TIMED_WAIT is not a problem the socket part is pretty clear.

Am not clear on your resources question - do you call pthread_exit() from main - or the equivalent of that- on signal receipt? Or are we talking signals you cannot block? pthread_cancel()?

Last edited by jim mcnamara; 04-14-2010 at 08:56 AM..
# 3  
Old 04-15-2010
Unfortunately I don't have a lot of exposure yet to pthreads.

I was looking for a a way to kill a thead in the fastest and no blocking way since I cannot call any blocking function to exit my.... so I was finding some KILL function able to kill a thread without having too much impact on the OS i.e. I am scared about having some socket left open /pending or some other kind of possible leakage caused by a BRUTAL killing of a thread...
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Programming

Killing a Child Thread

What is the best way for a parent to kill a child thread that has blocked on a command it cannot finish and will never read another line of its code? Will pthread_cancel() work with a thread that will never stop processing its current line of code? Thanks. (4 Replies)
Discussion started by: Brandon9000
4 Replies

2. IP Networking

thread blocked while deleting a socket.

Hello to all, I have below function, but the thread will be bloked at the line delete pListenSocket; // Close and delete If I put some cpu timing switching function prior to it, then no blocking pop up. printf("xyz\n"); // or sleep(100); delete pListenSocket; // Close and... (1 Reply)
Discussion started by: shinypro
1 Replies

3. AIX

SIGHUP killing Oracle Listener Process

I have a cold backup script which backs up my database and then restarts the oracle listener and database at around 01:30 I can see at this time that my database and listener are indeed running. However at around 02:17 my listener process receives a SIGHUP 1 signal from the AIX OS ( version 5.3 )... (2 Replies)
Discussion started by: jimthompson
2 Replies

4. IP Networking

Clarification - Setting socket options at the same time when socket is listening

I need clarification on whether it is okay to set socket options on a listening socket simultaneously when it is being used in an accept() call? Following is the scenario:- -- Task 1 - is executing in a loop - polling a listen socket, lets call it 'fd', (whose file descriptor is global)... (2 Replies)
Discussion started by: jake24
2 Replies

5. Shell Programming and Scripting

Finding the age of a unix process, killing old processes, killing zombie processes

I had issues with processes locking up. This script checks for processes and kills them if they are older than a certain time. Its uses some functions you'll need to define or remove, like slog() which I use for logging, and is_running() which checks if this script is already running so you can... (0 Replies)
Discussion started by: sukerman
0 Replies

6. Programming

Error with socket operation on non-socket

Dear Experts, i am compiling my code in suse 4.1 which is compiling fine, but at runtime it is showing me for socket programming error no 88 as i searched in errno.h it is telling me socket operation on non socket, what is the meaning of this , how to deal with this error , please... (1 Reply)
Discussion started by: vin_pll
1 Replies

7. Programming

socket function to read a webpage (socket.h)

Why does this socket function only read the first 1440 chars of the stream. Why not the whole stream ? I checked it with gdm and valgrind and everything seems correct... #include <stdio.h> #include <stdlib.h> #include <sys/types.h> #include <sys/stat.h> #include <string.h> #include... (3 Replies)
Discussion started by: cyler
3 Replies

8. UNIX for Advanced & Expert Users

connect problem for sctp socket (ipv6 socket) - Runtime fail Invalid Arguments

Hi, I was porting ipv4 application to ipv6; i was done with TCP transports. Now i am facing problem with SCTp transport at runtime. To test SCTP transport I am using following server and client socket programs. Server program runs fine, but client program fails giving Invalid Arguments for... (0 Replies)
Discussion started by: chandrutiptur
0 Replies

9. IP Networking

Can we write a multiple thread to receive from a single socket file descriptor

Hi Friends, I have written a program which will listener for more than 1000 requests per second from a single socket descriptor and then it will process those requestes. Its taking X amount of time. Now i want to reduce that time. Will I can write multiple threads to receive the... (2 Replies)
Discussion started by: pa.chidhambaram
2 Replies

10. Programming

How to implement the Listener thread

Listener thread is maintained at server side : I have Implemented as: /* specify queue */ listen(sockfd, 5); while (1) { clilen = sizeof(cli_addr); newsockfd = accept(sockfd, (struct sockaddr *) &cli_addr, &clilen); if... (0 Replies)
Discussion started by: shilpi_gup
0 Replies
Login or Register to Ask a Question