---
name: "sem_close"
section: "3"
platform: "linux"
package: "man-pages"
version: "6.19-1"
release: "Arch Linux 2026-11-01"
platforms: ["linux", "freebsd"]
url: "https://new.carta.tech/sem_close/3"
---

# sem\_close(3)

close a named semaphore

## NAME

sem\_close - close a named semaphore

## LIBRARY

POSIX threads library (*libpthread*, *-lpthread*)

## SYNOPSIS

```
#include <semaphore.h>
```

**int sem\_close(sem\_t \****sem***);**

## DESCRIPTION

**sem\_close**() closes the named semaphore referred to by *sem*, allowing any resources that the system has allocated to the calling process for this semaphore to be freed.

## RETURN VALUE

On success **sem\_close**() returns 0; on error, -1 is returned, with *errno* set to indicate the error.

## ERRORS

- **EINVAL**

  *sem* is not a valid semaphore.

## ATTRIBUTES

For an explanation of the terms used in this section, see [**attributes**(7)](/attributes/7.md).

| | | |
| --- | --- | --- |
| **Interface** | **Attribute** | **Value** |
| **sem\_close**() | Thread safety | MT-Safe |

## STANDARDS

POSIX.1-2008.

## HISTORY

POSIX.1-2001.

## NOTES

All open named semaphores are automatically closed on process termination, or upon [**execve**(2)](/execve/2.md).

## SEE ALSO

[**sem\_getvalue**(3)](/sem_getvalue/3.md), [**sem\_open**(3)](/sem_open/3.md), [**sem\_post**(3)](/sem_post/3.md), [**sem\_unlink**(3)](/sem_unlink/3.md), [**sem\_wait**(3)](/sem_wait/3.md), [**sem\_overview**(7)](/sem_overview/7.md)
