Skip to content

How to kill jobs by there job-id instead of there pid #4524

Answered by gforsyth
FranzAtGithub asked this question in Q&A
Discussion options

You must be logged in to vote

Copying from comment below:

You could do something like this in your xonshrc as a temporary fix:

from xonsh.jobs import _kill

def _xkill(args):
    taskid = int(args[0])
    job = __xonsh__.all_jobs.get(taskid)
    if job is None:
        raise XonshError(f"kill: sending signal to task-id: {taskid} failed: No such process")
    _kill(job)

aliases["xkill"] = _xkill

and then you can do this:

(base) gil@badcat ~ 🐚  jobs
[1]+ stopped: vim (43372)
(base) gil@badcat ~ 🐚  xkill 1
(base) gil@badcat ~ 🐚  jobs

If you wanted to roll something like this into xonsh itself, it would probably be best to have it be part of a subcommand of the jobs builtin, so you could run jobs kill <task-id> (anothe…

Replies: 3 comments 4 replies

Comment options

You must be logged in to vote
1 reply
@gforsyth
Comment options

Comment options

You must be logged in to vote
3 replies
@FranzAtGithub
Comment options

@gforsyth
Comment options

@FranzAtGithub
Comment options

Comment options

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