I have running python file "cepusender/main.py" (and another python files), how can i restart/kill only main.py file?
CodePudding user response:
Here's a way (there are many):
ps -ef | grep 'cepusender/main.py' | grep -v grep | awk '{print $2}' | xargs kill
psis the process snapshot command.-eprints every process on the system, and-fprints the full-format listing, which, germanely, includes the command line arguments of each process.grepprints lines matching a pattern. We firstgrepfor your file, which will match both thepythonprocess and thegrepprocess. We thengrep -v(invert match) forgrep, paring output down to just thepythonprocess.
Output now looks like the following:
user 77864 68024 0 13:53 pts/4 00:00:00 python file.py
- Next, we use awk to pull out just the second column of the output, which is the process ID or PID.
- Finally we use
xargsto pass the PID tokill, which asks thepythonprocess to shutdown gracefully.
CodePudding user response:
kill is the command to send signals to processes.
You can use kill -9 PID to kill your python process, where 9 is the number for SIGKILL and PID is the python Process ID.
