Question: I use SSH to connect to Linux, maybe run a Linux script multiple times, and use nohup to suspend these processes, and then close the SSH connection. After the next SSH connection to Linux, how can I distinguish between different scripts and get different PIDs?

This Linux script will always print content on the screen. I use Python's paramiko library, SSH to Linux, run the script and use nohup to suspend the process and redirect the output to the file. This process may be multiple times. How to distinguish the starting process, find its PID and kill it. It is best not to modify the Linux script because the script is not written by me.

I use the script name to find the process number, get a lot of PIDs, I can't distinguish them.

Answer: 
You could parse the output of [`ps -eo pid,lstart,cmd`](https://www.shellhacks.com/linux-ps-command-get-process-start-time-date/) which shows the process id, start time and path, e.g.:

```
  PID                  STARTED CMD
    1 Mon Jun 19 21:31:08 2017 /sbin/init
    2 Mon Jun 19 21:31:08 2017 [kthreadd]
    3 Mon Jun 19 21:31:08 2017 [ksoftirqd/0]

```

== Edit ==

Be aware that if the remote is macOS the `ps` command does not recognize the `cmd` keyword, use `comm` or `command` instead, e.g.: `ps -eo pid,lstart,comm`
maybe change the command you run to do something like:

```
nohup command.sh &
echo "$! `date`" >> runlog.txt
wait

```

i.e. run the command in the background, append its PID to a log (you might want to include more identifying information here or use a format that's more easily machine readable), then wait for it to finish

another variant would be to run `tmux` (GNU `screen`) on the server and run commands in an existing session:

```
tmux new-window command

```

which would also let you "reconnect" to running scripts later to check output / terminate