py-spy: "Killed: 9"?

Hello there,

Thank you for your work on the tool! I’m very excited to use it, but seem to have hit a snag:

17:12 ~/code/optimizely/src/www
$ pstree 98465
--- 98465 swilson /Users/swilson/code/optimizely/.virtualenv/www/test/bin/python /Users/swilson/code/optimizely/.virtualenv/www/test/bin/pytest --pdb services_test/client_tes [truncated]

17:13 ~/code/optimizely/src/www
$ sudo py-spy --pid 98465 -f hottt
Killed: 9

I’ve ensured that the PID of pytest isn’t moving around; i.e., it’s a long-running process with no child processes. Yet while it’s running, I get the output Killed: 9, exit status 137.

Python 2.7.12 py-spy 0.1.8 macOS 12.13.6

Let me know if I can provide any other details!

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 1
  • Comments: 20 (8 by maintainers)

Most upvoted comments

@crepererum I think that htop problem might be the same as this : https://jvns.ca/blog/2018/01/28/mac-freeze/ - which we should handle (with the sleep call here: https://github.com/rbspy/proc-maps/blob/96b274b826d7f9246856986af632b33672e9a7d9/src/mac_maps/mod.rs#L144 and I think apple has fixed the kernel bug in the macos version he’s using). The htop issue is mentioned on this twitter thread about that post anyways: https://twitter.com/b0rk/status/957498366606368768

@spencerwilson-optimizely I think this program should reproduce the problem (without all the other rust/py-spy code getting in the way and confusing the issue):

// file: task_for_pid_test.cc
#include <mach/mach_init.h>
#include <mach/port.h>
#include <stdio.h>
#include <stdlib.h>

int main(int argc, const char * argv[]) {
    if (argc <= 1) {
        printf("usage %s <pid>\n", argv[0]);
        return 1;
    }

    int pid = atoi(argv[1]);

    mach_port_name_t task = MACH_PORT_NULL;
    kern_return_t kr = task_for_pid(mach_task_self(), pid, &task);
    if (kr != KERN_SUCCESS) {
        printf("failed to call task_for_pid on pid %i: %x\n", pid, kr);
        return kr;
    }
    printf("success!\n");
    return 0;
}

compile with g++ task_for_pid_test.cc -o task_for_pid_test run with task_for_pid_test 12345 where 12345 is your pid.