---
name: "getsid"
section: "2"
platform: "macos"
package: "xnu"
version: "12377.121.6"
release: "macOS 26.5"
platforms: ["linux", "freebsd", "macos"]
url: "https://new.carta.tech/getsid"
---

# getsid(2)

get process session

## NAME

**getsid** – get process session

## LIBRARY

Standard C Library (libc, -lc)

## SYNOPSIS

**#include \<unistd.h\>**

*pid\_t*\

**getsid**(*pid\_t pid*);

## DESCRIPTION

The session ID of the process identified by *pid* is returned by **getsid**(). If *pid* is zero, **getsid**() returns the session ID of the current process.

## RETURN VALUES

Upon successful completion, the function **getsid**() returns the session ID of the specified process; otherwise, it returns a value of -1 and sets errno to indicate an error.

## ERRORS

The **getsid**() system call will fail if:

- \[ESRCH\]

  There is no process with a process ID equal to *pid*.

Note that an implementation may restrict this function call to processes within the same session ID as the calling process.

## SEE ALSO

[getpgid(2)](/getpgid/2.md), [getpgrp(2)](/getpgrp/2.md), [setpgid(2)](/setpgid/2.md), [setsid(2)](/setsid/2.md), [termios(4)](/termios/4.md)

## HISTORY

The **getsid**() function call appeared in FreeBSD 3.0. The **getsid**() function call is derived from its usage in AT&T System V UNIX.
