---
name: "rt_sem_trywait"
section: "2"
platform: "linux"
package: "rtlinux"
version: "2.0rel-1"
release: "Debian 2.2 (Potato)"
platforms: ["linux"]
url: "https://new.carta.tech/rt_sem_trywait"
---

# rt\_sem\_trywait(2)

semaphore 'wait' operation (without blocking)

## NAME

rt\_sem\_trywait - semaphore 'wait' operation (without blocking)

## SYNOPSIS

```
#define MODULE
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/version.h>
#include <linux/errno.h>
#include rt_ipc.h
```

**int rt\_sem\_trywait(rt\_sem\_t \****sem***);**

## DESCRIPTION

**rt\_sem\_wait** is the semaphore wait (sometimes known as 'take' or 'P') operation. Unlike  **rt\_sem\_wait**, **rt\_sem\_trywait** returns immediately whether or not the semaphore is available. *sem* points to the structure used in the call to **rt\_sem\_create**.

## RETURN VALUE

On success, 0 is returned.  On failure, a negative value is returned as described below.

## ERRORS

- **-EAGAIN**

  the semaphore is not currently available.

- **-EINVAL**

  *sem* does not point to a valid rt\_sem\_t.

## AUTHOR

Jerry Epplin \<JerryEpplin@worldnet.att.net\>

## SEE ALSO

[**rt\_task\_ipc\_delete**(2)](/rt_task_ipc_delete/2.md), [**rt\_task\_ipc\_init**(2)](/rt_task_ipc_init/2.md), [**rt\_sem\_destroy**(2)](/rt_sem_destroy/2.md), [**rt\_sem\_init**(2)](/rt_sem_init/2.md), [**rt\_sem\_post**(2)](/rt_sem_post/2.md), [**rt\_sem\_wait**(2)](/rt_sem_wait/2.md)
