如何定期中断c程序? [英] how to interrupt a c program periodically?

查看:60
本文介绍了如何定期中断c程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我编写一个运行许多任务的ANSI C程序

i需要运行一个调度程序,例如每1秒中断运行进程并运行某个程序,并在完成后返回以继续之前的中断调度程序。

i仅使用ANSI c,而不是c ++,用于项目约束,以及编译器c ++ builder 6,在windows 7环境下

i write an ANSI C program that run many tasks
i need to run a scheduler that interrupt the running process each 1second for example and run a certain program and after finishing it return back to continue the previously interrupted scheduler.
i use only ANSI c,not c++,for a project constraint,and compiler c++ builder 6 ,under windows 7 environment

推荐答案

我相信你可以使用Windows调度程序。检查Platform SDK以获取允许您管理流程的系统调用。


我不相信您需要自己编写调度程序,除非这是家庭作业的一部分。
I believe you can use the Windows scheduler for this. Check the Platform SDK for the system calls that allow you to manage your processes.

I don''t believe you need to write the scheduler yourself unless this is some part of a homework assignment.


调度程序是我项目的一部分,再次描述

我的算法是写一个主函数,它有一个无限循环什么都不做但是例如,每1分钟就会中断一次进程。

和我的问题是如何定期中断我的主要功能,当完成在windows环境下返回它时,在windows上进行模拟后嵌入式处理器的中断例程将用于真正的应用程序。
the scheduler is a part of my project ,a description again
my algorithm is to write a main function that is have an infinite cycle to do nothing but will be interrupted every 1 minute for example to run a set of process.
and my quistion is how to interrupt my main function periodically and when finish return back to it under windows environment,after this simulation on windows the interrupt routines for an embedded processor will be used in a really application.


你的prcesses在main()中生成的可能是线程。我不相信你可以有实际的进程,因为C无法访问OS调度程序。你通过系统调用来做到这一点。


所以在main()中你启动一个线程,然后启动一个计时器。当计时器到达秒时,你举起一个事件来停止线程。


线程当然必须在一个中断循环中寻找那个暂停事件。当它看到它时,它会进入内循环寻找恢复事件。当它看到它再次回到外部中断循环中寻找暂停事件时。


如果你在main()中有一个循环,你可以调用一系列启动定时器的函数然后是一个线程开始。


有点像服务器结构。


据推测,main可以读取包含名称的光盘文件要执行的进程加上任何运行时参数等
Your "prcesses" spawned in main() are probably threads. I don''t believe you can have actual processes since C has no access to OS scheduler. You do that through system calls.

So in main() you start a thread and then start a timer. When the timer reaches on second you raise an event to stop the thread.

The thread, of course, has to be in an interrupt loop looking for that pause event. When it sees it, it drops into an inner loop looking for the resume event. When it sees that it drops back into the outer interupt loop looking for the pause event again.

If you have a loop in main() you can call a series of functions that start timers followed by a thread start.

Kind of like a server structure.

Presumably, main could read a disc file that contains the names of the processes to execute plus any run-time parameters, etc.


这篇关于如何定期中断c程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆