About processes running in ubuntulinux 18.04 environment We are developing a program that checks the execution and termination status of the process and allows the process to be re-executed if it is terminated. (python3)
So I'm just trying to find the process with the shell command and check it as 0 or 1 to run the process.
import subprocess
mResult = subprocess.check_output("pgrep -lf processname | wc -l", shell=True) print('Result : ', int(mResult))
If you run it as an example, as shown above, If the returned mResult value is enabled, it will be 3 or 2. (The above values change at all times depending on the situation...)
However, if you enter 'pgrep -lf processname | wc -l' directly from the terminal, If it's running, it's returned to 1 or 0.
I would like to know the reason why it is returned to a completely different value when executed on Python.
Or if there is a better way to develop the above program, please help me.
python3 shell-script subprocess
We recommend that you program the system area with C rather than Python.
A pid directory is created under /proc, and you can use the information in this directory.
And if you want to use a command like grep, it's more efficient to write a shell script instead of Python.
578 Understanding How to Configure Google API Key
572 rails db:create error: Could not find mysql2-0.5.4 in any of the sources
617 Uncaught (inpromise) Error on Electron: An object could not be cloned
610 GDB gets version error when attempting to debug with the Presense SDK (IDE)
574 Who developed the "avformat-59.dll" that comes with FFmpeg?
© 2024 OneMinuteCode. All rights reserved.