# Is A Process Running?

**URL:** <https://racket.discourse.group/t/is-a-process-running/3548>\
**Category:** Questions & Answers\
**Created:** [February 7, 2025, 8:15pm UTC](https://racket.discourse.group/t/is-a-process-running/3548 "2025-02-07T20:15:16Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![OldDutchCap](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/olddutchcap/32/2037_2.png) [@OldDutchCap](https://racket.discourse.group/u/OldDutchCap)\
**Post date:** [February 7, 2025, 8:15pm UTC](https://racket.discourse.group/t/is-a-process-running/3548/1 "2025-02-07T20:15:16Z")

</div>

Just curious--is there some way in Racket to check if a given binary is running or not?

`(subprocess? )` doesn't seem to find the process I'm looking for. I mean I check by process-id and I get false and I check by name and I also get false. But I am trying it on Windows so I realize that might be part of the problem.

---

<div class="post-metadata">

**Author:** ![greghendershott](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/greghendershott/32/98_2.png) [@greghendershott](https://racket.discourse.group/u/greghendershott)\
**Post date:** [February 10, 2025, 2:11pm UTC](https://racket.discourse.group/t/is-a-process-running/3548/2 "2025-02-10T14:11:18Z")

</div>

Since no one has answered, let me help by offering a probably-mediocre answer that nudges someone else to improve it for you 😄

- I'm not aware that Racket offers a general, portable way to do this.

- Do you care about a process that you wrote and can modify, and you want to limit it to running once? If so, one idea: Use a file as a flag.

---

<div class="post-metadata">

**Author:** ![OldDutchCap](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/olddutchcap/32/2037_2.png) [@OldDutchCap](https://racket.discourse.group/u/OldDutchCap)\
**Post date:** [February 10, 2025, 4:52pm UTC](https://racket.discourse.group/t/is-a-process-running/3548/3 "2025-02-10T16:52:30Z")

</div>

Thanks Greg. I was hoping I was missing some simple Racket library call but if there's no easy way to do it then I can fudge something.

I think the .lock file is a good suggestion.

---

<div class="post-metadata">

**Author:** ![benknoble](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/benknoble/32/16_2.png) [@benknoble](https://racket.discourse.group/u/benknoble)\
**Post date:** [February 10, 2025, 5:48pm UTC](https://racket.discourse.group/t/is-a-process-running/3548/4 "2025-02-10T17:48:29Z")

</div>

`subprocess?` is a predicate on Racket values (mostly for those returned by `subprocess`) and is not like the (Unixy) `pgrep <name>`.

RE the lockfile, I think many package managers do something similar. I actually think there's system support for that via [https://docs.racket-lang.org/reference/Filesystem.html#%28def.\_%28%28lib.\_racket%2Ffile..rkt%29.\_call-with-file-lock%2Ftimeout%29%29](https://docs.racket-lang.org/reference/Filesystem.html#%28def._%28%28lib._racket%2Ffile..rkt%29._call-with-file-lock%2Ftimeout%29%29). If you use the same protocol in your binary, that might help.

---

<div class="post-metadata">

**Author:** ![soegaard](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/soegaard/32/19_2.png) [@soegaard](https://racket.discourse.group/u/soegaard)\
**Post date:** [February 10, 2025, 6:05pm UTC](https://racket.discourse.group/t/is-a-process-running/3548/5 "2025-02-10T18:05:17Z")

</div>

Could you solve the problem by invoking an external command?

---

<div class="post-metadata">

**Author:** ![OldDutchCap](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/olddutchcap/32/2037_2.png) [@OldDutchCap](https://racket.discourse.group/u/OldDutchCap)\
**Post date:** [February 10, 2025, 7:09pm UTC](https://racket.discourse.group/t/is-a-process-running/3548/6 "2025-02-10T19:09:18Z")

</div>

I might be able to do so. It's not worth that much trouble honestly. 🙂 As you may recall I've been hacking away at shell scripts in Racket and while I don't know for sure that it would cause a problem I was simply attempting to avoid spawning the same binary twice.

Since it's something I'm building solely for myself if I accidentally spawn the binary twice, it's not a catastrophe. 😃

---

<div class="post-metadata">

**Author:** ![LiberalArtist](https://yyz2.discourse-cdn.com/free1/user_avatar/racket.discourse.group/liberalartist/32/151_2.png) [@LiberalArtist](https://racket.discourse.group/u/LiberalArtist)\
**Post date:** [February 10, 2025, 7:48pm UTC](https://racket.discourse.group/t/is-a-process-running/3548/7 "2025-02-10T19:48:35Z")

</div>

> [@OldDutchCap](#):
>
> As you may recall I've been hacking away at shell scripts in Racket and while I don't know for sure that it would cause a problem I was simply attempting to avoid spawning the same binary twice.

If it's a process that you started from Racket:

1. using `subprocess`, you can use:
  - `subprocess-status` to poll;
  - `subprocess-wait` to block (potentially in a fresh thread); or
  - `sync` on the `subprocess?` value, in the general case;

2. using `process*` and friends, you can call the returned control procedure:
  - with `'status` to poll;
  - with `'wait` to block; or
  - with `'wait` in a fresh thread, to simulate `sync` on a `subprocess?` by using `thread-dead-evt`; or

3. using `system*` and friends, wait on a dedicated thread.

If you're interested in some arbitrary process, then you probably need to call a system API via the FFI, invoke a helper command, or use a protocol like @greghendershott and @benknoble described.

If you're interested in whether another instance of your application process is already running, e.g. to do something like “single instance” support for desktop applications, then you probably want some IPC mechanism, too, so maybe you use [`racket/unix-socket`](https://docs.racket-lang.org/unix-socket/index.html), or maybe you use your ability (or not) to listen on some application-specific TCP port as a flag.
