Skip to content

Conversation

@hebo1982
Copy link

@hebo1982 hebo1982 commented Aug 5, 2025

// child.c
max_cpu_time.rlim_cur = max_cpu_time.rlim_max = (rlim_t) ((_config->max_cpu_time + 1000) / 1000);
if (setrlimit(RLIMIT_CPU, &max_cpu_time) != 0) {
    CHILD_ERROR_EXIT(SETRLIMIT_FAILED);
}

setrlimit(RLIMIT_CPU, &max_cpu_time)

It will also exit in real execution time, and the if code block does not handle the case where real_time > max_cpu_time.

// runner.c
if (_config->max_cpu_time != UNLIMITED && _result->cpu_time > _config->max_cpu_time) {

reproduce json code for JudgerServer api:

{
    "language_config": {
        "compile": {
            "src_name": "main.cpp",
            "exe_name": "main",
            "max_cpu_time": 1000,
            "max_real_time": 2000,
            "max_memory": 1073741824,
            "compile_command": "/usr/bin/g++ -DONLINE_JUDGE -O2 -Werror=return-type -fmax-errors=3 -std=c++11 {src_path} -lm -o {exe_path}"
        },
        "run": {
            "command": "{exe_path}",
            "seccomp_rule": "c_cpp",
            "env": [
                "LANG=en_US.UTF-8",
                "LANGUAGE=en_US:en",
                "LC_ALL=en_US.UTF-8"
            ]
        }
    },
    "src": "#include <stdio.h>\nint main() {\n    int cnt1 = 0;\n    int cnt2 = 0; \n    int cnt3 = 0; \n    int cnt4 = 0;    \n    char c;\n\n    while ((c = getchar()) != '\\n') { \n        if ((c >= 'a' && c <= 'z') || (c >= 'A' && c <= 'Z')) {\n            cnt1++; \n        } else if (c == ' ') {\n            cnt2++; \n        } else if (c >= '0' && c <= '9') {\n            cnt3++; \n        } else {\n            cnt4++; \n        }\n    }\n    printf(\"英文字母:%d\\n\", cnt1);\n    printf(\"空格:%d\\n\", cnt2);\n    printf(\"数字:%d\\n\", cnt3);\n    printf(\"其他字符:%d\\n\", cnt4);\n    return 0;\n}\n",
    "max_cpu_time": 5000,
    "max_memory": 134217728,
    "output": true,
    "test_case": [
        {
            "input": "Hi everyone, my name is Li Na. I'm 18 years old and I love programming.",
            "output": "英文字母:51\n空格:14\n数字:2\n其他字符:4"
        }
    ]
}

response:

{
    "err": null,
    "data": [
        {
            "cpu_time": 2870,
            "real_time": 6000,
            "memory": 524288,
            "signal": 9,
            "exit_code": 0,
            "error": 0,
            "result": 4, // here should be "1" 
            "test_case": "1",
            "output_md5": null,
            "output": ""
        }
    ]
}

修复result超时状态错误
@hebo1982
Copy link
Author

hebo1982 commented Aug 6, 2025

@mikucat0309

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant