> For the complete documentation index, see [llms.txt](https://trizen.gitbook.io/sidef-lang/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://trizen.gitbook.io/sidef-lang/programming_tasks/d/determine_if_only_one_instance_is_running.md).

# Determine if only one instance is running

```ruby
# For this to work, you need to explicitly
# store the returned fh inside a variable.
var fh = File(__FILE__).open_r

# Now call the flock() method on it
fh.flock(File.LOCK_EX | File.LOCK_NB) ->
    || die "I'm already running!"

# Your code here...
say "Running..."
Sys.sleep(20)
say 'Done!'
```
