コード例 #1
0
JNIEXPORT jlong SIGAR_JNI(ptql_SigarProcessQuery_findProcess)
(JNIEnv *env, jobject obj, jobject sigar_obj)
{
    sigar_pid_t pid;
    int status;
    jni_ptql_re_data_t re;
    sigar_ptql_query_t *query =
        (sigar_ptql_query_t *)sigar_get_pointer(env, obj);
    dSIGAR(0);

    re_impl_set(env, sigar, obj, &re);

    status = sigar_ptql_query_find_process(sigar, query, &pid);

    sigar_ptql_re_impl_set(sigar, NULL, NULL);

    if (status < 0) {
        sigar_throw_exception(env, sigar->errbuf);
    }
    else if (status != SIGAR_OK) {
        sigar_throw_error(env, jsigar, status);
    }

    return pid;
}
コード例 #2
0
ファイル: rbsigar.c プロジェクト: weigon/sigar
static sigar_pid_t rb_sigar_pid_get(rb_sigar_t *rbsigar, VALUE obj)
{
    SIGAR;

    if (TYPE(obj) == T_STRING) {
        char *pid = StringValuePtr(obj);

        if (sigar_isdigit(*pid)) {
            obj = rb_str2inum(obj, 10);
            /* fallthru */
        }
        else if ((RSTRING_LEN(obj) == 2) &&
                 (*pid == '$') && (*(pid + 1) == '$'))
        {
            return sigar_pid_get(sigar);
        }
        else {
            /* XXX cache queries */
            sigar_ptql_query_t *query;
            sigar_ptql_error_t error;
            int status =
                sigar_ptql_query_create(&query, (char *)pid, &error);

            if (status == SIGAR_OK) {
                sigar_pid_t qpid;

                sigar_ptql_re_impl_set(sigar, NULL, rbsigar_ptql_re_impl);
                status = sigar_ptql_query_find_process(sigar, query, &qpid);
                sigar_ptql_re_impl_set(sigar, NULL, NULL);
                sigar_ptql_query_destroy(query);
                if (status == SIGAR_OK) {
                    return qpid;
                }
                else {
                    RB_SIGAR_RAISE(sigar_strerror(sigar, status));
                }
            }
            else {
                RB_SIGAR_RAISE(error.message);
            }
        }
    }
    return NUM2UINT(obj);
}