我如何:主线程生成子线程,哪个子进程...控制这些子进程? [英] How do I: Main thread spawn child threads, which child processes...control those child processes?

查看:88
本文介绍了我如何:主线程生成子线程,哪个子进程...控制这些子进程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这就是我想做的事情:


有一个主守护进程,可以在Boss-Queue结构中启动多个线程。


从这些线程中,我希望他们都坐下来看队列。一旦条目

进入队列,抓住它并运行系统命令。


现在我想确保系统命令没有挂起永远,所以我需要一些

方法来杀死命令并让工作线程回去工作等待另外的队列条目




现在交叉的原因是因为它可以在没有线程的情况下完成。

我想弄清楚如何去做,一个非阻塞的open()不知何故?我刚刚想到了popen(),但是如何以非阻塞的方式这样做?


有什么想法吗?


杰夫

Here''s what I want do:

Have a main daemon which starts up several threads in a Boss-Queue structure.

From those threads, I want them all to sit and watch a queue. Once an entry
goes into the queue, grab it and run a system command.

Now I want to make sure that system command doesn''t hang forever, so I need some
way to kill the command and have the worker thread go back to work waiting for
another queue entry.

Now the reason for the crossposting is because it could be done without threads.
I''m trying to figure out how to go about it, a non-blocking open() somehow? I
just now thought of popen(), but how to do so in a non-blocking way?

Any thoughts?

Jeff

推荐答案

2003年12月4日星期四23:32:41 -0700,Jeff Rodriguez

< ne ******** @ gurugeek.EXAMPLENOSPAM.com>在comp.lang.c中写道:


将来请在你的交叉发布列表中留下comp.lang.c

在询问平台特定问题时它们是偏离主题的。
On Thu, 04 Dec 2003 23:32:41 -0700, Jeff Rodriguez
<ne********@gurugeek.EXAMPLENOSPAM.com> wrote in comp.lang.c:

In the future please leave comp.lang.c out of your cross-post list
when asking platform specific questions, they are off-topic h ere.
这就是我想做的事:

有一个主守护进程启动一个Boss中的几个线程-Queue结构。
Here''s what I want do:

Have a main daemon which starts up several threads in a Boss-Queue structure.




C语言中没有守护进程或线程。


-

Jack Klein

主页: http://JK-Technology.Com

常见问题解答

comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html

comp.lang。 c ++ http://www.parashift.com/c++-faq-lite/

alt.comp.lang.learn.c-c ++ ftp://snurse-l.org/pub/acllc-c++/faq



There are no daemons or threads in the C language.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++ ftp://snurse-l.org/pub/acllc-c++/faq


这是一个真实的粗略示例使用popen()。我经常使用这种

技术。


{

FILE *正在运行;


running = popen(" ls -l"," r");


if(running)

{

fd_set rFds = {0};

int nFds = -1;


FD_SET(fileno(正在运行),& rFds);

nFds = select(1 + fileno(正在运行),& rFds,0,0,0);

switch(nFds)

{

/ *解码这里发生的事情* /

}

}

}


我建议你使用poll()进行等待(对于

例子,select()更容易)。然后你可以等到你想要的时间,并且关闭运行

应该发出一个破裂的管道到达过程,从而终止它。


我不喜欢我知道你是否需要与其他

过程进行双向互动,但理论仍然是相同的,你只需要处理其他行为。在popen()调用之前处理


Jeff Rodriguez写道:
Here is a real rough example on how to use popen(). I use this
technique quite often.

{
FILE *running;

running = popen("ls -l","r");

if (running)
{
fd_set rFds = {0};
int nFds = -1;

FD_SET(fileno(running),&rFds);
nFds = select(1+fileno(running),&rFds,0,0,0);
switch(nFds)
{
/* decode what happended here */
}
}
}

I''d recommend you use poll() for waiting (select() is easier for the
example). Then you can wait as long as you wish, and closing running
should signal a broken pipe to the process, thus terminating it.

I don''t know if you need bi directional interaction with the other
process, but the theory will still be the same, you just need to handle
the "other" handle before the popen() call

Jeff Rodriguez wrote:
这就是我想做的事:

有一个主守护进程在Boss-Queue
结构中启动多个线程。

从这些线程中,我希望他们都坐下来看队列。一旦
条目进入队列,抓住它并运行系统命令。

现在我想确保系统命令不会永远挂起,所以我
需要一些方法来终止命令并让工作线程返回
工作等待另一个队列条目。

现在交叉的原因是因为它可以在没有
线程。我想弄清楚如何去做,一个非阻塞的
open()不知何故?我刚刚想到popen(),但是如何以非阻塞的方式这样做?

任何想法?

杰夫
Here''s what I want do:

Have a main daemon which starts up several threads in a Boss-Queue
structure.

From those threads, I want them all to sit and watch a queue. Once an
entry goes into the queue, grab it and run a system command.

Now I want to make sure that system command doesn''t hang forever, so I
need some way to kill the command and have the worker thread go back to
work waiting for another queue entry.

Now the reason for the crossposting is because it could be done without
threads. I''m trying to figure out how to go about it, a non-blocking
open() somehow? I just now thought of popen(), but how to do so in a
non-blocking way?

Any thoughts?

Jeff






***粗鲁的帖子固定。后续设定。 ***


Joseph Dionne写道:
*** Rude top-posting fixed. Follow-ups set. ***

Joseph Dionne wrote:
Jeff Rodriguez写道:
Jeff Rodriguez wrote:

有一个主守护进程启动Boss-Queue
结构中的几个线程。

从这些线程中,我希望他们都坐下来看队列。一旦条目进入队列,抓住它并运行系统命令。

现在我想确保系统命令不会永远挂起,
所以我需要一些方法来杀死命令并让工作线程返回工作,等待另一个队列输入。

现在交叉的原因是因为它可以完成
没有线程。我想弄清楚如何去做,
无阻塞打开()不知何故?我刚刚想到popen(),但是
如何以非阻塞方式这样做?

Have a main daemon which starts up several threads in a Boss-Queue
structure.

From those threads, I want them all to sit and watch a queue. Once
an entry goes into the queue, grab it and run a system command.

Now I want to make sure that system command doesn''t hang forever,
so I need some way to kill the command and have the worker thread
go back to work waiting for another queue entry.

Now the reason for the crossposting is because it could be done
without threads. I''m trying to figure out how to go about it, a
non-blocking open() somehow? I just now thought of popen(), but
how to do so in a non-blocking way?



这是一个关于如何使用popen()的真实粗略示例。我经常使用这种技术。

{...文件*正在运行;

running = popen(" ls -l"," r" ;);

如果(运行)
{
fd_set rFds = {0};
int nFds = -1;

FD_SET (fileno(running),& rFds);
nFds = select(1 + fileno(running),& rFds,0,0,0);
switch(nFds)
{
/ *解码这里发生的事情* /
}
}

我建议您使用poll()进行等待(选择( )这个例子更容易)。然后你可以等到你想要的时间,并且关闭
运行应该发出一个破裂的管道进入过程,从而终止它。

我不知道你是否需要与其他过程进行双向互动,但理论仍然是相同的,你只需要处理其他过程。在popen()调用之前处理



Here is a real rough example on how to use popen(). I use this
technique quite often.

{
FILE *running;

running = popen("ls -l","r");

if (running)
{
fd_set rFds = {0};
int nFds = -1;

FD_SET(fileno(running),&rFds);
nFds = select(1+fileno(running),&rFds,0,0,0);
switch(nFds)
{
/* decode what happended here */
}
}
}

I''d recommend you use poll() for waiting (select() is easier for
the example). Then you can wait as long as you wish, and closing
running should signal a broken pipe to the process, thus
terminating it.

I don''t know if you need bi directional interaction with the other
process, but the theory will still be the same, you just need to
handle the "other" handle before the popen() call




这个线程完全不是c.l.c的主题,因为C

语言知道关于线程的zip。 C.l.c.也不宽恕

热门发布。


-

查克F(cb ******** @ yahoo.com)(cb********@worldnet.att.net)

可用于咨询/临时嵌入式和系统。

< http ://cbfalconer.home.att.net>使用worldnet地址!



This thread is entirely off topic for c.l.c, inasmuch as the C
language knows zip about threads. C.l.c. also does not condone
top-posting.

--
Chuck F (cb********@yahoo.com) (cb********@worldnet.att.net)
Available for consulting/temporary embedded and systems.
<http://cbfalconer.home.att.net> USE worldnet address!


这篇关于我如何:主线程生成子线程,哪个子进程...控制这些子进程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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