Skip to content

How can I get the PID of a background process in a Xonsh script? #5310

Closed Answered by ading2210
ading2210 asked this question in Q&A
Discussion options

You must be logged in to vote

I've found a workaround for this using the xonsh.jobs module:

import xonsh

def get_last_job():
  jobs = list(xonsh.jobs.get_jobs().values())
  if not jobs:
    return None
  last_job = max(jobs, key=lambda x: x["started"])
  return last_job

sleep 10 &
j = get_last_job()

kill @(j["pids"][0])
kill @(j["pids"][0]) #no such process

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by anki-code
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
1 participant