简体   繁体   English

如何实时运行无限循环-Linux?

[英]How to run an infinite loop in real time - Linux?

I wrote a hello world program with an infinite loop with Xenomai API, as follows: This gets terminated soon. 我用Xenomai API编写了一个带有无限循环的hello world程序,如下所示:该程序很快终止。

I actually wanted to test this program's real time latency through latencytop . 我实际上想通过latencytop测试该程序的实时延迟。
How to run an infinite loop in real time? 如何实时运行无限循环?

RT_TASK demo_task;

void demo(void *arg)
{
    RT_TASK *curtask;
    RT_TASK_INFO curtaskinfo;

    curtask=rt_task_self();
    rt_task_inquire(curtask,&curtaskinfo);

    printf("Task name : %s \n", curtaskinfo.name);

        //------------------ hello world --------------------
    while (1)
    {
        printf("Hello World!\n");
    }

}

int main(int argc, char* argv[])
{
    char  str[10];

    rt_print_auto_init(1);

    mlockall(MCL_CURRENT|MCL_FUTURE);

    printf("start task\n");

    sprintf(str,"hello");
    rt_task_create(&demo_task, str, 0, 50, 0);

    rt_task_start(&demo_task, &demo, 0);
}

At the bottom of main, also put an infinite loop. 在主体的底部,还放置了无限循环。 while(1) sleep(10000) is usually good on full-blown linux, don't know about RT-world. while(1)sleep(10000)通常在成熟的Linux上很好,而对RT-world则一无所知。

What's happening is that you're spawning off a new task and then main is immediately returning after this, which exits the entire process. 发生的情况是,您正在生成一个新任务,然后main在此之后立即返回,从而退出了整个过程。

I agree: 我同意:

What's happening is that you're spawning off a new task and then main is immediately returning after this, which exits the entire process. 发生的情况是,您正在生成一个新任务,然后main在此之后立即返回,从而退出了整个过程。

But, IMO, should you use rt_task_join() at the end of main to 但是,IMO,您应该在main的末尾使用rt_task_join()

Wait on the termination of a real-time task. 等待实时任务终止。 [1] [1]

[1] https://xenomai.org/documentation/trunk/html/api/group__task.html [1] https://xenomai.org/documentation/trunk/html/api/group__task.html

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM