'Get PID of the debugged process
Returns:
- pid (Int)'

@memoized
def getpid(self):

    out = None
    status = self.get_status()
    if ((not status) or (status == 'STOPPED')):
        return None
    if self.is_target_remote():
        ctx = config.Option.get('context')
        config.Option.set('context', None)
        try:
            out = self.execute_redirect('call    getpid()')
        except:
            pass
        config.Option.set('context', ctx)
        if (out is None):
            return None
        else:
            out = self.execute_redirect('print    $')
            if out:
                return to_int(out.split('=')[1])
            else:
                return None
    pid = gdb.selected_inferior().pid
    return (int(pid) if pid else None)
