I have a macbook (default shell is zsh)
I have an executable python script (srcript1.py).
I use another executable script (called starter) that runs script1.py when my computer starts, the terminal window that runs starter opens and closes automatically and the script1.py process remains running as a separate process. (starter is runed automatically through an instance of a szh shell when my computer is turned on). The original starter script file is as follows:
#!/bin/bash
cd /script1; nohup ./script1.py &
This script works okay and everything is good.
However, I'm trying to understand what happens when I use (&&) instead of (;) in my script. i.e
#!/bin/bash
cd /scritp1 && nohup ./script1.py &
My issue is that this also works but whenever I try to kill my python script's process I notice that the terminal instance of szh or something else (probably a bash process) is in running as a process. I.e if I call ps in terminal I get
ps -ef | grep "script1"
123 14679 1 0 2:12PM ?? 0:00.00 /bin/bash /script1 starter
123 14680 14679 0 2:12PM ?? 0:03.46 /PythonFolder/python ./script1.py
123 14690 14683 0 2:12PM ttys000 0:00.00 grep scrip1
For the script starter that uses &&
and
ps -ef | grep "script1"
123 14644 1 0 2:08PM ?? 0:03.46 /PythonFolder/python ./script1.py
123 14652 14647 0 2:08PM ttys000 0:00.00 grep scrip1
For the starter script using ;
Why do I get two processes in one version and only one in the other? I'm trying to understand why does the szh that runs starter creates a child process running my python script when I use && and why does it terminate when my starter script uses ; and leaves the python script running as a single process.
When I run starter with the script that uses && the terminal app appears and closes but leaves two running processes (14679 and 14680 in this case).
If I use the starter script using ; and I want to kill my python.py process I would just call
kill 14644
But if I use the starter script that uses && and I want to kill both processes I noticed that killing the child process or killing the parent and then the child process work, ie
kill 14680
or
kill 14679; kill 14680
I also noted that I can kill the parent process
kill 14679
and my python script would continue running as usual.