I have an issue when programming on Solaris 10 and hope to ask for help here. I have created a script to call-on "ssh" binary. This script runs some checks before running the "ssh" binary as a subprocess. The script assumes the power of "root" via SUID method.
After using this script for some time, some of the processes are left hanging like below.
root 23322 1 0 12:24:38 ? 0:00 scriptssh device321
I have logined to device321 and found no other users existing in the device.
After some read-up, I realize that the script has disconnected itself from the controlling terminal (look at the ? at "tty" and 1 at "PPID"). Is this a fallacy of subprocess in Python if I use the "communicate" method?
Anyone have a method to resolve this or identify why is this happening?
The script is written in Python.
EDIT:
Maybe it is easier to highlight the issue like this:
User A login to remote server -> SSH session is created
User A logout of remote server -> SSH session remains
SSH session eats up high CPU on current server.
Below is some snippets of the codes.
def main():
....
....
try:
if logic_user(username) == "privilege":
if ip_check(src_ip,p_list):
ssh_out(ssh_exe)
else:
print("You do not have access to SSH")
except KeyboardInterrupt:
print("Ctrl+c keyed in")
finally:
print("\nexiting ssh")
def ssh_out(ssh_exe):
cmd = subprocess.Popen(ssh_exe, shell=True)
cmd.communicate()