# Detect if GPIO is in use by other Legato App

**URL:** <https://forum.legato.io/t/detect-if-gpio-is-in-use-by-other-legato-app/3574>\
**Category:** Legato Application Framework\
**Created:** [August 21, 2018, 2:41am UTC](https://forum.legato.io/t/detect-if-gpio-is-in-use-by-other-legato-app/3574 "2018-08-21T02:41:56Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![davidc](https://avatars.discourse-cdn.com/v4/letter/d/a183cd/32.png) [@davidc](https://forum.legato.io/u/davidc)\
**Post date:** [August 21, 2018, 2:41am UTC](https://forum.legato.io/t/detect-if-gpio-is-in-use-by-other-legato-app/3574/1 "2018-08-21T02:41:56Z")

</div>

Hiya,

Is there any way to detect if a GPIO already has a handler attached?

According to the doc (and testing):

> The client will be killed for below scenarios:
> 
> - Only one handler can be registered per pin. Subsequent attempts to register a handler will result in the client being killed.

ciao, Dave

---

<div class="post-metadata">

**Author:** ![andcor](https://avatars.discourse-cdn.com/v4/letter/a/9de0a6/32.png) [@andcor](https://forum.legato.io/u/andcor)\
**Post date:** [August 21, 2018, 6:58am UTC](https://forum.legato.io/t/detect-if-gpio-is-in-use-by-other-legato-app/3574/2 "2018-08-21T06:58:37Z")

</div>

Generally, if you are not using the GPIO, noone is. But you can always search the legato source code for the api name, that should give you all the candidates for conflicts if any.

---

<div class="post-metadata">

**Author:** ![davidc](https://avatars.discourse-cdn.com/v4/letter/d/a183cd/32.png) [@davidc](https://forum.legato.io/u/davidc)\
**Post date:** [August 21, 2018, 7:07am UTC](https://forum.legato.io/t/detect-if-gpio-is-in-use-by-other-legato-app/3574/3 "2018-08-21T07:07:59Z")

</div>

Hiya,

Ta.

Sorry - I wasn’t clear - I am looking for a way to do it at run-time.

ciao, Dave

---

<div class="post-metadata">

**Author:** ![andcor](https://avatars.discourse-cdn.com/v4/letter/a/9de0a6/32.png) [@andcor](https://forum.legato.io/u/andcor)\
**Post date:** [August 21, 2018, 7:09am UTC](https://forum.legato.io/t/detect-if-gpio-is-in-use-by-other-legato-app/3574/4 "2018-08-21T07:09:10Z")

</div>

Why would you need to do that ? Do you have a case where you don’t know if anyone else is using the GPIO or do you just want to be safe by checking before using ?

---

<div class="post-metadata">

**Author:** ![davidc](https://avatars.discourse-cdn.com/v4/letter/d/a183cd/32.png) [@davidc](https://forum.legato.io/u/davidc)\
**Post date:** [August 21, 2018, 7:21am UTC](https://forum.legato.io/t/detect-if-gpio-is-in-use-by-other-legato-app/3574/5 "2018-08-21T07:21:24Z")

</div>

Hi,

I may have a case where more than one app _may_ try to use a GPIO … depending on user configuration.

Trying to catch it gracefully/safely - rather than just have the app explode.

ciao, Dave

---

<div class="post-metadata">

**Author:** ![andcor](https://avatars.discourse-cdn.com/v4/letter/a/9de0a6/32.png) [@andcor](https://forum.legato.io/u/andcor)\
**Post date:** [August 21, 2018, 7:50am UTC](https://forum.legato.io/t/detect-if-gpio-is-in-use-by-other-legato-app/3574/6 "2018-08-21T07:50:46Z")

</div>

I have a use case where multiple threads read the gpio state and therefore I had to ditch the legato gpio system for controlling gpios and go directly on the /sys/class/gpio files. That is the only graceful solution I have found

---

<div class="post-metadata">

**Author:** ![davidc](https://avatars.discourse-cdn.com/v4/letter/d/a183cd/32.png) [@davidc](https://forum.legato.io/u/davidc)\
**Post date:** [August 21, 2018, 11:48am UTC](https://forum.legato.io/t/detect-if-gpio-is-in-use-by-other-legato-app/3574/7 "2018-08-21T11:48:07Z")

</div>

Hiya,

Yeah, I’ve had to do that too - but I needed to do it for speed rather than isolation/protection issues.

I think I might have to re-implement a GPIO service that directly interfaces with /sys/class/gpio to manage input/output states and mux them between apps.

Thanks for your thoughts. Much appreciated.

ciao, Dave
