LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel
User Name
Password
Linux - Kernel This forum is for all discussion relating to the Linux kernel.

Notices


Reply
  Search this Thread
Old 03-25-2007, 01:04 PM   #1
raga4223688
LQ Newbie
 
Registered: Feb 2007
Posts: 11

Rep: Reputation: 0
Question How to free a socket????


I recently ran a program...but abruptly stopped it using Cntrl + Z....Now the sockets i used in it (Internet domain sockets) were not free....When i again tried to run the same program it gave me error "Cant bind sockets".....I used netstat to check whether the socket is there...it was there with state CLOSED_WAIT...Now is there any command or way to clean/free/remove these unwanted sockets!!!!!!!!!!!
 
Old 03-25-2007, 03:54 PM   #2
Unknown_User
Member
 
Registered: Jan 2003
Location: EU (UK)
Distribution: Ubuntu 14.x, Raspbian, Kali
Posts: 226

Rep: Reputation: 30
Use the close() command.

http://linux.about.com/library/cmd/blcmdl2_close.htm

http://www.rt.com/man/socket.4.html
 
Old 03-27-2007, 03:32 PM   #3
Mara
Moderator
 
Registered: Feb 2002
Location: Grenoble
Distribution: Debian
Posts: 9,696

Rep: Reputation: 232Reputation: 232Reputation: 232
Remember that you need to wait a while after closing a listening socket to bind to the same port number.
 
Old 03-28-2007, 11:24 AM   #4
raga4223688
LQ Newbie
 
Registered: Feb 2007
Posts: 11

Original Poster
Rep: Reputation: 0
Can u tell me wat signal is generated when u kill a program using Cntrl+Z ...is it SIGINT or SIGKILL??? So can the solution be to capture these signals and close the desired socket???
 
Old 03-29-2007, 03:01 AM   #5
sayarsoft
LQ Newbie
 
Registered: Aug 2006
Posts: 6

Rep: Reputation: 0
When you strace your program you will see that you get SIGTSTP when you pres C+Z.

As a solution to your problem :

setsockopt with SO_REUSEADDR your socket descriptor before bind. So you can bind at the next run.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
connection between java socket and unix socket sathishkumar Programming 1 01-10-2006 03:21 PM
fseek on a socket descriptor to discard socket buffer? Thinking Programming 1 12-06-2005 09:15 PM
cannot read data at server socket, though client socket sends it jacques83 Linux - Networking 0 11-15-2005 01:58 PM
Single Socket Vs Multiple Socket Kumar Programming 1 10-05-2005 10:02 AM
Unable to connect to UNIX socket /tmp/.esd/socket error while using grip dr_zayus69 Linux - Software 4 08-23-2005 07:28 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software > Linux - Kernel

All times are GMT -5. The time now is 06:27 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration