user1061392
user1061392

Reputation: 324

run a process from script and kill it from another script using PID

I want to run a process from script and kill it from another script using PID. I can think of two things to do but I think you can help me get more effective way of doing this. The first one is to store the PID in temp file and read it from the other script. The other way is to save it as environment variable from the first script and use it by the other script. I am very sure there is nicer way of doing this. I used killall and pkill to kill the process by the process name. However, this did not work good. I want to kill it using PID.

Upvotes: 1

Views: 384

Answers (2)

Bee Kay
Bee Kay

Reputation: 319

Creating a PID or a .lck file is always a best practice. You're the owner of the identifier as well as the script, so you can plan to prevent other problems creeping in, such as another user attempting to start up the same application.

Upvotes: 0

freshvolk
freshvolk

Reputation: 81

I would suggest using the first method you talked about. Creating a temp .pid file with the information on the process is a very common way to track the PID of a running process. It is easy to do in most languages and pretty straightforward.

The second could create an issue because depending on what shell you use, that environment variable may be difficult to ensure that it is global and not touched.

Upvotes: 1

Related Questions