Skip to content

Commit

Permalink
Merge pull request #138 from doronz88/feature/process_control_send_plist
Browse files Browse the repository at this point in the history
add send signal to process control
  • Loading branch information
doronz88 committed Sep 13, 2021
2 parents a996050 + a04703f commit f7d1d8c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 0 deletions.
17 changes: 17 additions & 0 deletions pymobiledevice3/cli/developer.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,10 @@
import shlex
from collections import namedtuple
from dataclasses import asdict
import signal

import click
from click.exceptions import MissingParameter, UsageError
from pykdebugparser.pykdebugparser import PyKdebugParser
from pymobiledevice3.services.dvt.instruments.screenshot import Screenshot
from termcolor import colored
Expand Down Expand Up @@ -98,6 +100,21 @@ def applist(lockdown: LockdownClient, color):
print_json(apps, colored=color)


@dvt.command('signal', cls=Command)
@click.argument('pid', type=click.INT)
@click.argument('sig', type=click.INT, required=False)
@click.option('-s', '--signal-name', type=click.Choice([s.name for s in signal.Signals]))
def send_signal(lockdown, pid, sig, signal_name):
""" Send SIGNAL to process by its PID """
if not sig and not signal_name:
raise MissingParameter(param_type='argument|option', param_hint='\'SIG|SIGNAL-NAME\'')
if sig and signal_name:
raise UsageError(message='Cannot give SIG and SIGNAL-NAME together')
sig = sig or signal.Signals[signal_name].value
with DvtSecureSocketProxyService(lockdown=lockdown) as dvt:
ProcessControl(dvt).signal(pid, sig)


@dvt.command('kill', cls=Command)
@click.argument('pid', type=click.INT)
def kill(lockdown: LockdownClient, pid):
Expand Down
9 changes: 9 additions & 0 deletions pymobiledevice3/services/dvt/instruments/process_control.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,15 @@ class ProcessControl:
def __init__(self, dvt):
self._channel = dvt.make_channel(self.IDENTIFIER)

def signal(self, pid: int, sig: int):
"""
Send signal to process
:param pid: PID of process to send signal.
:param sig: SIGNAL to send
"""
self._channel.sendSignal_toPid_(MessageAux().append_obj(sig).append_obj(pid), expects_reply=True)
return self._channel.receive_plist()

def kill(self, pid: int):
"""
Kill a process.
Expand Down

0 comments on commit f7d1d8c

Please sign in to comment.