Sponsored Content
Top Forums Shell Programming and Scripting Terminate processes for CLOSE_WAIT status of TCP Post 302760759 by EAGL€ on Thursday 24th of January 2013 02:33:41 PM
Old 01-24-2013
Terminate processes for CLOSE_WAIT status of TCP

Hello Friends,

First of all im sorry for spending extra space in DB of forum with this thread, i know there would be a solution if i kept searching,

I need to terminate the process which causes CLOSE_WAIT status of TCP connection via port 8103:

Code:
-bash-3.00$ netstat -na | grep 8103
127.0.0.1.8103       127.0.0.1.63876      49152      0 49152      0 CLOSE_WAIT
127.0.0.1.8103       127.0.0.1.39286      49152      0 49152      0 CLOSE_WAIT
127.0.0.1.8103       127.0.0.1.60796      49152      0 49152      0 CLOSE_WAIT
      *.8103               *.*                0      0 49152      0 LISTEN
127.0.0.1.8103       127.0.0.1.62363      49152      0 49152      0 CLOSE_WAIT

I found this script FPMurphy posted on a thread here but i couldnt make it work for Solaris:

Code:
PORT=8103
PIDS=`ps -ef | sed 1d | awk '{print $2}'`
for pid in $PIDS
do
        /usr/proc/bin/pfiles $pid 2>/dev/null | grep -q "port: $PORT"
        if [[ $? -eq 0 ]] ; then
               echo "Port: $PORT is being used by PID: \c" 
                           ps -o pid -o args -p $PID | sed 1d
        fi
done

Function of grep -q in Linux is not provided on solaris.. So i got this:
Code:
grep: illegal option -- q
Usage: grep -hblcnsviw pattern file . . .

So i tried below part with xargs even without being sure about how exact output of "/usr/proc/bin/pfiles $pid" part seems like, im sorry a bit stuck with time...

Code:
PORT=8103
PIDS=`ps -ef | sed 1d | awk '{print $2}'`
for pid in $PIDS
do
        /usr/proc/bin/pfiles $pid 2>/dev/null | xargs grep "port: $PORT"
        if [[ $? -eq 0 ]] ; then
               echo "Port: $PORT is being used by PID: \c"
                           ps -o pid -o args -p $PID | sed 1d
        fi
done

I had this meaningless output:

Code:
grep: can't open 23534:
grep: can't open -bash
grep: can't open Current
grep: can't open rlimit:
grep: can't open 256
grep: can't open file
grep: can't open descriptors
grep: can't open 0:
grep: can't open S_IFCHR
grep: can't open mode:0600
grep: can't open dev:292,0
grep: can't open ino:12582922
grep: can't open uid:100

Any suggestion welcome,

Thanks in advance,
Kind Regards
 

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

retrieving exit status from background processes

Hi, I need to retrieve the exit status of 4 moves running as background processes. The wait command will not work since it can only give me the exit status of the last of the background processes. Here's a sample of what I need !#/bin/ksh mv /dir1/subdir1/*.Z /dir6/subdir6/ & mv... (2 Replies)
Discussion started by: MG537
2 Replies

2. UNIX for Advanced & Expert Users

clear CLOSE_WAIT status

Hi, I have an application with a bug in it that keeps sockets in CLOSE_WAIT, which eventually freezes the server because the user account it runs under runs out of file handles. We have the bug fixed but can only release the fix with the next release. Does anyone know how I can clear the... (3 Replies)
Discussion started by: rein
3 Replies

3. UNIX for Dummies Questions & Answers

How to check the status of the processes running for the current user?

Hi All, I am new to unix. Can anyone tell me "How to check the status of the processes running for the current user?" Regards, Ravindaran S (1 Reply)
Discussion started by: ravind27
1 Replies

4. Programming

How to check TCP server status

Please tell me according to C/C++ socket programming; how client can check whether server is running or not during TCP communication. (1 Reply)
Discussion started by: mansoorulhaq
1 Replies

5. Programming

TCP status question

There is a server and a client,when client send a message to server,server can send a reply to client. The status of server and client is ESTABLISHED.Then I halt the client,I find the server status is CLOSE_WAIT and the client status is FIN_WAIT_2. Many minutes passed,I find the the server status... (1 Reply)
Discussion started by: konvalo
1 Replies

6. Red Hat

How to kill a TCP connection which has status TIME_WAIT & no PID

Hi, I want to kill TCP connections which have status as TIME_WAIT & no PID (as per the output of the "netstat - p" command). Is there any command/utility available to kill connections to a specific port or IP address. The problem is that these connections don't have process ID (see... (4 Replies)
Discussion started by: Davinder31may
4 Replies

7. Programming

Getting TCP Port status through C API

Does anyone know if there is a C API call to get the status of a TCP port? As opposed to running netstat and parsing the results. At the moment I have to attempt to bind() and pick up on the address in use error which isn't very elegant Thanks ---------- Post updated at 10:42 AM ----------... (0 Replies)
Discussion started by: janra
0 Replies

8. Shell Programming and Scripting

Executing multiple processes without waiting for their exit status.

Hello Friends, Hope you are doing well. I just need a help in executing multiple processes. I've written a shell script which calls another scritps. But the problem is there are too many processes to run, and each process takes about a min to finish its execution. So, I want to just... (3 Replies)
Discussion started by: singh.chandan18
3 Replies

9. UNIX for Dummies Questions & Answers

Processes and exit status

Hi, I can't understand why the last $? is 1? can somebody plz help me to understand it? thanks $ ksh $ ps -f UID PID PPID C STIME TTY TIME COMMAND msarabad 12361 12319 0 15:17:58 pts/1 0:00 ksh msarabad 12319 12317 0 15:15:11 pts/1 0:00 -sh msarabad 12362 12361 ... (7 Replies)
Discussion started by: messi777
7 Replies

10. AIX

How to repair a TCP/IP socket in state: CLOSE_WAIT?

Hi The clients connect to my server -using port 9130. But no client could connect to my server at this time. I've checked already and this is the result netstat -Aan|grep -v 127.0.0.1|grep 9130|pg f10006000abcb398 tcp4 10313 0 10.0.89.81.9130 10.158.70.24.1705 CLOSE_WAIT... (8 Replies)
Discussion started by: bobochacha29
8 Replies
kill(1) 						      General Commands Manual							   kill(1)

NAME
kill - send a signal to a process; terminate a process SYNOPSIS
signame] pid ... signum] pid ... Obsolescent Versions: DESCRIPTION
The command sends a signal to each process specified by a pid process identifier. The default signal is which normally terminates pro- cesses that do not trap or ignore the signal. Options recognizes the following options: List all values of signame supported by the implementation. No signals are sent with this option. The symbolic names of the signals (without the prefix) are written to standard output, separated by spaces and newlines. Send the specified signal name. The default is number signame can be specified in upper- and/or lowercase, with or without the prefix. These val- ues can be obtained by using the option. The symbolic name represents signal value zero. See "Signal Names and Numbers" below. Send the specified decimal signal number. The default is See "Signal Names and Numbers" below. (Obsolescent.) Equivalent to (Obsolescent.) Equivalent to Operands pid is a process identifier, an unsigned or negative integer that can be one of the following: The number of a process. All processes, except special system processes, whose process group ID is equal to the process group ID of the sender. All processes, except special system processes, if the user has appropriate privileges. Otherwise, all processes, except special system processes, whose real or effective user ID is the same as the user ID of the sending process. All processes, except special system processes, whose process group ID is equal to the absolute value of pid and whose real or effective user ID is the same as the user of the sending process. Process numbers can be found with the command (see ps(1)) and with the built-in command available in some shells. Signal Names and Numbers The following table describes a few of the more common signals that can be useful from a terminal. For a complete list and a full descrip- tion, see the header file and the manual entry signal(5). signum signame Name Description ---------------------------------------------------------------------------- 0 SIGNULL Null Check access to pid 1 SIGHUP Hangup Terminate; can be trapped 2 SIGINT Interrupt Terminate; can be trapped 3 SIGQUIT Quit Terminate with core dump; can be trapped 9 SIGKILL Kill Forced termination; cannot be trapped 15 SIGTERM Terminate Terminate; can be trapped 24 SIGSTOP Stop Pause the process; cannot be trapped 25 SIGTSTP Terminal stop Pause the process; can be trapped 26 SIGCONT Continue Run a stopped process the null signal, invokes error checking but no signal is actually sent. This can be used to test the validity or existence of pid. the (default) terminate signal, can be trapped by the receiving process, allowing the receiver to execute an orderly shutdown or to ignore the signal entirely. For orderly operations, this is the preferred choice. the kill signal, forces a process to terminate immediately. Since cannot be trapped or ignored, it is useful for terminating a process that does not respond to The receiving process must belong to the user of the sending process, unless the user has appropriate privileges. As a single special case, the continue signal SIGCONT can be sent to any process that is a member of the same session as the sending process. RETURN VALUE
Upon completion, returns with one of the following values: At least one matching process was found for each pid operand, and the specified signal was successfully processed for at least one matching process. An error occurred. EXAMPLES
The command: signals process number 6135 to terminate. This gives the process an opportunity to exit gracefully (removing temporary files, etc.). The following equivalent commands: terminate process number 6135 abruptly by sending a signal to the process. This tells the kernel to remove the process immediately. WARNINGS
If a process hangs during some operation (such as I/O) so that it is never scheduled, it cannot die until it is allowed to run. Thus, such a process may never go away after the kill. Similarly, defunct processes (see ps(1)) may have already finished executing, but remain on the system until their parent reaps them (see wait(2)). Using to send signals to them has no effect. Some non-HP-UX implementations provide only as a shell built-in command. DEPENDENCIES
This manual entry describes the external command and the built-in command of the POSIX shell (see sh-posix(1)). Other shells, such as C and Korn (see csh(1) and ksh(1) respectively), also provide as a built-in command. The syntax for and output from these built-ins may be different. SEE ALSO
csh(1), ksh(1), ps(1), sh(1), sh-posix(1), kill(2), wait(2), signal(5). STANDARDS CONFORMANCE
kill(1)
All times are GMT -4. The time now is 01:57 PM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy