Sponsored Content
Special Forums Cybersecurity Getting PID of Open Connectivity Post 302097406 by DraconianTimes on Friday 24th of November 2006 07:04:01 AM
Old 11-24-2006
fstat might help you here. In OpenBSD,
Code:
fstat | grep ':22' | awk '{print $3}' | uniq

This will search the fstat output for port 22, and then awk will give you the third column which is the PID for the process bound to the specified port. Replace 22 with whatever port number you are binding to (don't forget to leave in the colon symbol) and you should get the info you need. Column output and command line switches might be different! =)

Nick
 

7 More Discussions You Might Find Interesting

1. Programming

printing ppid,child pid,pid

question: for the below program i just printed the value for pid, child pid and parent pid why does it give me 6 values? i assume ppid is 28086 but can't figure out why there are 5 values printed instead of just two! can someone comment on that! #include<stdio.h> #define DIM 8 int... (3 Replies)
Discussion started by: a25khan
3 Replies

2. UNIX for Dummies Questions & Answers

Session PID & socket connection pid

1. If I use an software application(which connects to the database in the server) in my local pc, how many PID should be registered? Would there be PID for the session and another PID for socket connection? 2. I noticed (through netstat) that when I logged in using the my software application,... (1 Reply)
Discussion started by: pcx26
1 Replies

3. Shell Programming and Scripting

KILL PID, intern should kill another PID.

Hi All, In my project i have two process runs in the back end. Once i start my project, and execute the command ps, i get below output: PID TTY TIME CMD 9086 pts/1 0:00 ksh 9241 pts/1 0:02 java 9240 pts/1 0:00 shell_script_bg java with 9241 PID is the main... (4 Replies)
Discussion started by: rkrgarlapati
4 Replies

4. UNIX for Dummies Questions & Answers

how to find the owner PID of open socket on Solaris9?

Hi all, I am trying to connect the open socket and its owner PID on my Solaris9 system. But it seems not very easy. As netstat is not as powerful as it is on Linux platform, without the "-program" option, and "lsof -i <UDP|TCP>@<hostIP>" won't show the one i want although it lists some... (1 Reply)
Discussion started by: sleepy_11
1 Replies

5. UNIX for Dummies Questions & Answers

Need to get pid of a process and have to store the pid in a variable

Hi, I need to get the pid of a process and have to store the pid in a variable and i want to use this value(pid) of the variable for some process. Please can anyone tell me how to get the pid of a process and store it in a variable. please help me on this. Thanks in advance, Amudha (7 Replies)
Discussion started by: samudha
7 Replies

6. Red Hat

cannot set user id: Resource temporarily unavailable (not open file/open process related)

First post, sorry to be a bother but this one has been dogging me. I have a process user (java application server) that trips a resource limit every couple weeks and need help finding what limit we're hitting. First, this is what's running: This is the error when jobs are run or the... (0 Replies)
Discussion started by: Katahdin
0 Replies

7. Shell Programming and Scripting

Closing open file descriptors from /proc/pid/fd

Hi guys, i need to write a shell script that will close file descriptors from /proc/pid/fd will calling exec 4<&- solve the problem ? thanks in advance :) (15 Replies)
Discussion started by: alpha_romeo
15 Replies
explain_fstat(3)					     Library Functions Manual						  explain_fstat(3)

NAME
explain_fstat - explain fstat(2) errors SYNOPSIS
#include <libexplain/fstat.h> const char *explain_fstat(int fildes, struct stat *buf); const char *explain_errno_fstat(int errnum, int fildes, struct stat *buf); void explain_message_fstat(char *message, int message_size, int fildes, struct stat *buf); void explain_message_errno_fstat(char *message, int message_size, int errnum, int fildes, struct stat *buf); DESCRIPTION
These functions may be used to obtain explanations for errors returned by the fstat(2) system call. explain_fstat const char *explain_fstat(int fildes, struct stat *buf); The explain_fstat function is used to obtain an explanation of an error returned by the fstat(2) system call. The least the message will contain is the value of strerror(errno), but usually it will do much better, and indicate the underlying cause in more detail. The errno global variable will be used to obtain the error value to be decoded. This function is intended to be used in a fashion similar to the following example: if (fstat(fildes, buf) < 0) { fprintf(stderr, "%s ", explain_fstat(fildes, buf)); exit(EXIT_FAILURE); } fildes The original fildes, exactly as passed to the fstat(2) system call. buf The original buf, exactly as passed to the fstat(2) system call. Returns: The message explaining the error. This message buffer is shared by all libexplain functions which do not supply a buffer in their argument list. This will be overwritten by the next call to any libexplain function which shares this buffer, including other threads. Note: This function is not thread safe, because it shares a return buffer across all threads, and many other functions in this library. explain_errno_fstat const char *explain_errno_fstat(int errnum, int fildes, struct stat *buf); The explain_errno_fstat function is used to obtain an explanation of an error returned by the fstat(2) system call. The least the message will contain is the value of strerror(errnum), but usually it will do much better, and indicate the underlying cause in more detail. This function is intended to be used in a fashion similar to the following example: if (fstat(fildes, buf) < 0) { int err = errno; fprintf(stderr, "%s ", explain_errno_fstat(err, fildes, buf)); exit(EXIT_FAILURE); } errnum The error value to be decoded, usually obtained from the errno global variable just before this function is called. This is neces- sary if you need to call any code between the system call to be explained and this function, because many libc functions will alter the value of errno. fildes The original fildes, exactly as passed to the fstat(2) system call. buf The original buf, exactly as passed to the fstat(2) system call. Returns: The message explaining the error. This message buffer is shared by all libexplain functions which do not supply a buffer in their argument list. This will be overwritten by the next call to any libexplain function which shares this buffer, including other threads. Note: This function is not thread safe, because it shares a return buffer across all threads, and many other functions in this library. explain_message_fstat void explain_message_fstat(char *message, int message_size, int fildes, struct stat *buf); The explain_message_fstat function may be used to obtain an explanation of an error returned by the fstat(2) system call. The least the message will contain is the value of strerror(errno), but usually it will do much better, and indicate the underlying cause in more detail. The errno global variable will be used to obtain the error value to be decoded. This function is intended to be used in a fashion similar to the following example: if (fstat(fildes, buf) < 0) { char message[3000]; explain_message_fstat(message, sizeof(message), fildes, buf); fprintf(stderr, "%s ", message); exit(EXIT_FAILURE); } message The location in which to store the returned message. If a suitable message return buffer is supplied, this function is thread safe. message_size The size in bytes of the location in which to store the returned message. fildes The original fildes, exactly as passed to the fstat(2) system call. buf The original buf, exactly as passed to the fstat(2) system call. explain_message_errno_fstat void explain_message_errno_fstat(char *message, int message_size, int errnum, int fildes, struct stat *buf); The explain_message_errno_fstat function may be used to obtain an explanation of an error returned by the fstat(2) system call. The least the message will contain is the value of strerror(errnum), but usually it will do much better, and indicate the underlying cause in more detail. This function is intended to be used in a fashion similar to the following example: if (fstat(fildes, buf) < 0) { int err = errno; char message[3000]; explain_message_errno_fstat(message, sizeof(message), err, fildes, buf); fprintf(stderr, "%s ", message); exit(EXIT_FAILURE); } message The location in which to store the returned message. If a suitable message return buffer is supplied, this function is thread safe. message_size The size in bytes of the location in which to store the returned message. errnum The error value to be decoded, usually obtained from the errno global variable just before this function is called. This is neces- sary if you need to call any code between the system call to be explained and this function, because many libc functions will alter the value of errno. fildes The original fildes, exactly as passed to the fstat(2) system call. buf The original buf, exactly as passed to the fstat(2) system call. SEE ALSO
fstat(2) get file status explain_fstat_or_die(3) get file status and report errors COPYRIGHT
libexplain version 0.52 Copyright (C) 2008 Peter Miller explain_fstat(3)
All times are GMT -4. The time now is 08:47 AM.
Unix & Linux Forums Content Copyright 1993-2022. All Rights Reserved.
Privacy Policy