Question

I have a CLI application of which I can run multiple instances simultaneously. I need to associate a unique, sequential and re-usable identifier to each instance. It should also be contextual/independent for each process type.

Example:

  • The first, second and third instances get ids 0, 1 and 2, respectively.
  • Now if the second instance dies and another instance comes up, that new instance should be given id 1 since it was "freed" by the dying instance.
  • If I run a different process type, I should be given id 0.

The obvious choice would be to use the processes' PID but that would give me too many different and too sparse identifiers.

Is there something built-in in Unix/Linux or some service that gives me that?

I would prefer a system native or Node.js solution.

Background:

I'm using Graphite to generate stats of an application and I don't want to potentially create thousands of buckets of the same stats using the processes' PIDs. If there's an alternative solution to this problem, I would also be interested in knowing that.

Thank you!

Was it helpful?

Solution

Since I didn't find any system that meets my requirements, I have created an app myself and hosted it at GitHub: https://github.com/muzzley/process-id-dealer

It's a Node.js app that deals sequential and reusable process ids through an HTTP endpoint. Thus, it can be used by any other program.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top