<!--
{
  "availability" : [
    "macOS: 10.7.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "XPC",
  "identifier" : "/documentation/XPC/xpc_connection_get_pid(_:)",
  "metadataVersion" : "0.1.0",
  "role" : "Function",
  "symbol" : {
    "kind" : "Function",
    "modules" : [
      "XPC"
    ],
    "preciseIdentifier" : "c:@F@xpc_connection_get_pid"
  },
  "title" : "xpc_connection_get_pid(_:)"
}
-->

# xpc_connection_get_pid(_:)

Returns the PID of the remote peer.

```
func xpc_connection_get_pid(_ connection: xpc_connection_t) -> pid_t
```

## Parameters

`connection`

The connection object which is to be examined.

## Return Value

The PID of the remote peer.

## Discussion

A given PID is not guaranteed to be unique across an entire boot cycle. Great care should be taken when dealing with this information, as it can go stale after the connection is established. macOS recycles PIDs, and therefore another process could spawn and claim the PID before a message is actually received from the connection.

XPC will deliver an error to your event handler if the remote process goes away, but there are no guarantees as to the timing of this notification’s delivery either at the kernel layer or at the XPC layer.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)