1

I have a couple cli-based scripts that run for some time.

I'd like another script to 'restart' those other scripts.

I've checked SO for answers, but the scenarios were not applicable enough to mine, as I'm trying to end Terminal processes using Terminal.

Process:

  1. 2 cli-based scripts are running (node, python, etc).
  2. 3rd script is run and decides whether or not to restart the other 2. This can't quit Terminal, but has to end current processes.
  3. 3rd script then runs an executable that restarts everything.

Currently none of the terminal windows are named, and from reading the other posts, I can see that it may be helpful to do so.

I can mostly set this up, I just could not find a command that would end all other terminal processes and close them.

Karric
  • 1,415
  • 2
  • 19
  • 32
  • 1
    Have you considered the third script (your step 2) starting the 2 scripts as child processes (step 1) and then killing the processes and restarting when appropriate? – Hawkins Jun 17 '18 at 18:49
  • Why is *restart* in quotes? Are you quoting someone, or do you mean the script shouldn't actually do it, just try to look like it's trying? – tripleee Jun 18 '18 at 06:45

2 Answers2

1

There are a couple of ways to do this. Most common is having a pidfile. This file contains the process ID (pid) of the job you want to kill later on. A simple way to create the pidfile is:

$ node server &
$ echo $! > /tmp/node.pidfile

$! contains the pid of the process that was most recently backgrounded.

Then later on, you kill it like so:

$ kill `cat /tmp/node.pidfile`

You would do similar for the python script.

The other less robust way is to do a killall for each process and assume you are not running similar node or python jobs.

Refer to What is a .pid file and what does it contain? if you're not familiar with this.

tk421
  • 5,775
  • 6
  • 23
  • 34
0

The question headline is quite general, so is my reply killall bash

or generically killall processName

eg. killall chrome

FantomX1
  • 1,577
  • 2
  • 15
  • 23