Skip to content

check the parent pid of the spawned process #2584

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions agent/test_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -720,3 +720,22 @@ def test_pinning(self):
assert r.status_code == 500
js = r.json()
assert js["message"] == "Agent has already been pinned to an IP!"

def test_parent_pid_sync(self):
"""Confirm if the spawned process has agent as parent"""
# The output line endings are different between linux and Windows.
file_contents = (
f"# Comment a random number {random.randint(1000, 9999)}'",
"import os",
"print(f'process_id:{os.getpid()}')",
"print(f'parent_pid:{os.getppid()}')",
)
filepath = self.store_file(file_contents)

form = {"filepath": filepath}
js = self.post_form("execpy", form)
agent_pid = self.agent_process.pid
assert js["message"] == "Successfully executed command"
assert "stdout" in js
assert "process_id" in js["stdout"]
assert f"parent_pid:{agent_pid}" in js["stdout"]
Loading