0

How can i get pid of process which established a socket. I went through this PDF link, where he has mentioned Calling fcntl() with F_SETOWN and the pid of our process to tell the process that it is the owner of the socket.How can i get socket owner using fcntl()?

  • `The owner of a socket is unset when a socket is created. The owner may be set to a process ID or process group ID using the F_SETOWN command of the fcntl() function.` as mentioned in [this link](http://pubs.opengroup.org/onlinepubs/000095399/functions/xsh_chap02_10.html). To get the pid of your own process you can use `getpid()`. – 0xF1 Apr 25 '14 at 07:02

1 Answers1

0

From the man pagr of fcntl()

F_SETOWN (int) Set the process ID or process group ID that will receive SIGIO and SIGURG signals for events on file descriptor fd to the ID given in arg. A process ID is specified as a positive value; a process group ID is specified as a negative value. Most commonly, the calling process specifies itself as the owner (that is, arg is specified as getpid(2)).

You can use the getpid() to get the process ID. And on passing that to F_SETOWN, you are requesting that the the process be notified if the SD is readable or writable.

Specifically the answer to your titled question is getpid().

Prabhu
  • 3,443
  • 15
  • 26