0

I have a script that looks like this:

#!/bin/bash

tsx watch services/$1/src/index.ts

This will start tsc for the given service:

script/start_service some-service

If I add & the end it gets executed as a job:

script/start_service some-service &

but I still get some output. Then if I redirect (all) its output to /dev/null:

 script/start_service some-service > /dev/null 2>&1 &

it starts the service properly in the background, but I can't look it up after my script returns.

What I'm trying to figure out is how to add a name (or some other unique identifier) to the job I start so that I can look it up later from another script (and possibly terminate it if necessary).

Note that this question is related, but I can't figure out how to apply the answer to my use case. The answer:

bash -c "exec -a MyUniqueProcessName <command> &"

doesn't work for me. No matter what I do I don't get a process with the name I passed.

Note that the reason why I don't just assign the pid to a variable is that my script terminates and whenever the user calls my script again it needs to check which services are running at the moment and it doesn't have access to the ephemeral local variables that would have been created by the previous execution of the script.

Adam Arold
  • 175
  • 2
  • 3
  • 12

0 Answers0