简体   繁体   English

一个线程执行多个进程

[英]Many processes executed by one thread

Is something like the following possible in C on Linux platform: I have a thread say A reading system calls(intercepting system calls) made by application processes.在 Linux 平台上的 C 中是否可能出现以下情况:我有一个线程说 A 读取应用程序进程进行的系统调用(拦截系统调用)。 For each process A creates a thread, which performs the required system call and then sleeps till A wakes it up with another system call which was made by its corresponding application process.对于每个进程,A 创建一个线程,该线程执行所需的系统调用,然后休眠,直到 A 用其相应应用程序进程进行的另一个系统调用将其唤醒。 When a process exits, it worker thread ceases to exist.当一个进程退出时,它的工作线程不再存在。

So its like a number of processes converzing on a thread which then fans out to many threads with one thread per process.因此,它就像多个进程在一个线程上进行对话,然后将其扇出到多个线程,每个进程一个线程。

Thanks谢谢

If you are looking for some kind of threadpool implementation and are not strictly limited to C I would recommend threadpool (which is almost Boost).如果您正在寻找某种线程池实现并且不严格限于C ,我会推荐线程池(几乎是 Boost)。 Its easy to use and quite lean.它易于使用且非常精简。 The only logic you now need is the catching of the system event and then spawn a new task thread that will execute the call.您现在需要的唯一逻辑是捕获系统事件,然后生成一个将执行调用的新任务线程。 The threadpool will keep track of all created threads and assign work automatically to the threads.线程池将跟踪所有创建的线程并自动将工作分配给线程。

EDIT编辑

Since you are limited to C, try this implementation .由于您仅限于 C,请尝试此实现 It looks fairly complete and rather simple, but it will basically do the job.它看起来相当完整且相当简单,但它基本上可以完成这项工作。

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

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