How do I: Main thread spawn child threads, which child processes...control those child processes?

J

Jeff Rodriguez

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
 
J

Jack Klein

On Thu, 04 Dec 2003 23:32:41 -0700, Jeff Rodriguez

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.
Here's what I want do:

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

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
 
J

Joseph Dionne

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

CBFalconer

*** Rude top-posting fixed. Follow-ups set. ***

Joseph said:
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

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.
 
B

Bjorn Reese

[ comp.lang.c added back in ]

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.

As a reader of comp.unix.programmer, where the thread is
relevant, may I humbly ask you lot on comp.lang.c to practice
what you preach by not cross-posting your replies about the
charter of comp.lang.c, which is off-topic on the other groups?

Thank you.
 
K

Kevin Goodsell

Bjorn said:
[ comp.lang.c added back in ]

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.


As a reader of comp.unix.programmer, where the thread is
relevant, may I humbly ask you lot on comp.lang.c to practice
what you preach by not cross-posting your replies about the
charter of comp.lang.c, which is off-topic on the other groups?

Sorry, no. That's not a reasonable request. It does no good for us to
tell others in comp.lang.c that a message is off-topic here while people
in other groups merrily cross post more and more off-topic replies to
our group. When somebody cross-posts an off-topic message, we have to
ask the other groups to remove us from the cross-post list when
replying. I expect people in any other group to do the same, and
certainly wouldn't complain if a member of some other group replied to a
cross post in c.l.c to tell us that the thread is not topical in their
group. In fact, it's nice to know, since it removes all doubt about
whether a reply should be cross-posted back to that group or not.

We in comp.lang.c do our best to be good neighbors. We're sorry for the
noise, but blame the original cross-poster, not us.

Disclaimer: I don't speak for the whole group. Any or all of the other
members of c.l.c may disagree with me.

-Kevin
 
B

Barry Margolin

Kevin Goodsell said:
We in comp.lang.c do our best to be good neighbors. We're sorry for the
noise, but blame the original cross-poster, not us.

No you don't, and I don't think you're sorry. I've never seen any other
group be so routinely hostile to innocent newbies who don't know any
better. Their thinking was probably something like "I'm programming on
Unix in C, so I'll ask in the Unix and C groups." Is that *so*
unreasonable that they need to be made to feel like idiots?

You can clearly see that the message is cross-posted to a Unix group.
Then when it makes mention of a Unix function (which you probably knew
was going to happen) you typically give some kind of sarcastic response,
embarassing them as if they're the first one to ever have made this
mistake.

We occasionally get questions in comp.unix.programmer that are about
straight C, with nothing Unix-specific. I've rarely seen anyone here
respond "Sorry, that's not a Unix question, go ask in comp.lang.c." We
answer them, and then perhaps mention your fine newsgroup (as well as
some related alt.learn groups, if it seems appropriate) for future
questions of the same type.

You guys are like a grumpy neighbor. Kids don't want their ball to get
thrown into his yard by accident, because he won't give it back without
a fight.
 
M

Mark McIntyre

No you don't, and I don't think you're sorry.

You misjudge Kevin in specific, and CLC in general.
I've never seen any other
group be so routinely hostile to innocent newbies who don't know any
better.

There are for sure some people here who're overagressive. Its
certainly far from the most hostile group tho.
Their thinking was probably something like "I'm programming on
Unix in C, so I'll ask in the Unix and C groups." Is that *so*
unreasonable that they need to be made to feel like idiots?

Go not to the elves for counsel, for they shall say "newbies ought to
follow nettiquette and lurk before posting, and yet by definition
newbies may not know that"
We occasionally get questions in comp.unix.programmer that are about
straight C, with nothing Unix-specific. I've rarely seen anyone here
respond "Sorry, that's not a Unix question, go ask in comp.lang.c." We
answer them,

Probably because any straight C question is by definition entirely
within the scope of unix programming?
 
B

Bjorn Reese

our group. When somebody cross-posts an off-topic message, we have to
ask the other groups to remove us from the cross-post list when
replying. I expect people in any other group to do the same, and
certainly wouldn't complain if a member of some other group replied to a
cross post in c.l.c to tell us that the thread is not topical in their

All other groups that I am subscribed to uses a different tactic
to handle off-topic postings; they ignore them. Only comp.lang.c
feels compelled to teach everybody about their charter.

As long as comp.lang.c uses their tactic within their own group
I am not going to object, but I have a problem when they
cross-post to other groups, and set the follow-up to all groups
except their own group. Discussions about the charter of
comp.lang.c are topical on comp.lang.c and only there, so the
follow-up should be set to comp.lang.c and not any other group.
We in comp.lang.c do our best to be good neighbors. We're sorry for the
noise, but blame the original cross-poster, not us.

The original poster will be educated about the comp.lang.c charter
by the replies that are sent exclusively to comp.lang.c.

Should any replies omit to remove comp.lang.c from the cross-
posting then I am sorry about the noise, but at least you have
the posibility to killfile the thread -- we don't because the
thread, apart from the postings about what is topical on
comp.lang.c, is topical on our groups.

I do not perceive the comp.lang.c charter cross-posting, nor your
refusal to respect the charters of other groups, as good
neighborship.

Please respect the fact that discussions about what is and is not
topical on comp.lang.c are not topical on other groups.

Thank you.
 
M

Mark McIntyre

All other groups that I am subscribed to uses a different tactic
to handle off-topic postings; they ignore them. Only comp.lang.c
feels compelled to teach everybody about their charter.

actually, we don't have one - the group predates the charter system.
As long as comp.lang.c uses their tactic within their own group
I am not going to object, but I have a problem when they
cross-post to other groups, and set the follow-up to all groups
except their own group. Discussions about the charter of
comp.lang.c are topical on comp.lang.c and only there, so the
follow-up should be set to comp.lang.c and not any other group.

agreed.
The original poster will be educated about the comp.lang.c charter
by the replies that are sent exclusively to comp.lang.c.

only if he reads it.
 
A

Arthur J. O'Dwyer

All other groups that I am subscribed to uses a different tactic
to handle off-topic postings; they ignore them. Only comp.lang.c
feels compelled to teach everybody about their charter.

No charter for c.l.c -- it's been around longer than the charter
system, apparently. We do have a FAQ or two, though.
As long as comp.lang.c uses their tactic within their own group
I am not going to object, but I have a problem when they
cross-post to other groups, and set the follow-up to all groups
except their own group.

The rationale for that is: This is off-topic on c.l.c, but not
c.u.p.
Suppose I (in c.l.c) do nothing. Then c.l.c is flooded with
off-topic posts cross-posted from c.u.p. That's bad.
Suppose I (in c.l.c) post a message to c.l.c only, telling the
OP it's off-topic. That might educate the OP, but probably not --
he doesn't read c.l.c. (If he did, he wouldn't post OT questions
here. QED.) And since nobody in c.u.p will see the message, it
won't stop the flood of OT posts either.
Suppose I (in c.l.c) post a message to c.u.p only, telling the
OP it's off-topic. That has a higher chance of educating the OP,
but it would be uncouth -- because without any post in c.l.c, the
members won't see that the OP has been re-directed, and *c.u.p*
will be flooded by c.l.c redirection messages!
Suppose I (in c.l.c) post a message to c.u.p and c.l.c both,
telling the OP it's off-topic. That will probably educate the
OP (since he must be reading *some* group), and if all goes well
it will be noticed by the folks in c.u.p too, and they will stop
posting OT stuff to c.l.c.
Setting the followups to exclude c.l.c keeps the OT (sub-)thread
from reappearing in the newsgroup in which it is OT. Unfortunately,
it *is* counter-productive, in that it tends to piss off people
in other groups, who then flood c.l.c with threads like this
one, complaining about how the followup list was pared.
Discussions about the charter of
comp.lang.c are topical on comp.lang.c and only there, so the
follow-up should be set to comp.lang.c and not any other group.

Reasonable. The central problem, the Catch-22, is that we
can't get rid of an annoying thread without re-directing the poster,
and we can't re-direct the poster without risking the start of
another annoying sub-thread like this one.
If only everyone would read the FAQs and some general guides
to Usenet etiquette, we would hardly ever have this problem. I
tend to agree with you -- c.l.c *is* a grumpy old man into whose
yard it is unwise to hit baseballs. But it's only gotten that way
because *every week* a new kid moves into the house next door and
the *first* thing he does is hit a baseball through our window.
*Every week.* It produces a bit of institutionalized grumpiness
after a while.
FWIW, many of the newbies who post *only* to c.l.c get redirected
in a more friendly manner. That may be due partly to the fact that
we know that after they get redirected, the thread will *die*, and
not be kept alive by some idjits in a whole 'nother group who have
The original poster will be educated about the comp.lang.c charter
by the replies that are sent exclusively to comp.lang.c.

No, he obviously *won't*. He doesn't *read* c.l.c -- if he ever
had, he'd have seen the kinds of questions that are topical here.
And if he ever *planned* to read c.l.c, he'd have Googled the FAQ
himself. Thus we can only conclude that he must be reading from
your side of the fence. Sorry.
Should any replies omit to remove comp.lang.c from the cross-
posting then I am sorry about the noise, but at least you have
the posibility to killfile the thread -- we don't because the
thread, apart from the postings about what is topical on
comp.lang.c, is topical on our groups.

Yes, I'm sorry about that too. Catch-23: If we added a
[TOPICALITY] tag to the thread, then c.u.p could killfile it.
But if we change the subject line, then Google Groups will
spawn a new thread and the OP might not see the sub-thread at
all -- and thus he'd keep doing it. :-(
I do not perceive the comp.lang.c charter cross-posting, nor your
refusal to respect the charters of other groups, as good
neighborship.

Please respect the fact that discussions about what is and is not
topical on comp.lang.c are not topical on other groups.

I highly doubt that the original topicality-policeman *intended*
to start a "discussion." We just want the things that are off-topic
on *our* group to stay *out*. Discussion is not necessary. (Catch-
24: I can't impart my information to you unless I join the
discussion. And the information I want to impart is that discussion
is counter-productive.)

Now please everyone let this thread die. And next time you see
an off-topic thread in c.u.p (or anywhere), just re-direct the OP
and then shut up. And remember, in your redirection, to tell the
OP to shut up too, lest we start another of *these*. :)

-Arthur
 
K

Kevin Goodsell

Barry said:
No you don't, and I don't think you're sorry. I've never seen any other
group be so routinely hostile to innocent newbies who don't know any
better. Their thinking was probably something like "I'm programming on
Unix in C, so I'll ask in the Unix and C groups." Is that *so*
unreasonable that they need to be made to feel like idiots?

First, groups aren't hostile. (Some) people are.

Second, if the "newbies" observed some basic netiquette rules then there
wouldn't be a problem. c.l.c provides countless man-hours of free
support, and asks nothing in return. All that we ask is that people
follow the basic rules of Usenet. When they don't, some people become
hostile.
You can clearly see that the message is cross-posted to a Unix group.
Then when it makes mention of a Unix function (which you probably knew
was going to happen) you typically give some kind of sarcastic response,
embarassing them as if they're the first one to ever have made this
mistake.

Yes, I can clearly see the cross-post list. But it's also easy to miss.
I assume that most of the time when a response like that is
cross-posted, it's because the person didn't realize that the original
message (or their reply) was being cross-posted. Personally, I usually
post a polite reply addressing the other groups and asking them to
remove comp.lang.c from the cross-post list when replying.
We occasionally get questions in comp.unix.programmer that are about
straight C, with nothing Unix-specific. I've rarely seen anyone here
respond "Sorry, that's not a Unix question, go ask in comp.lang.c." We
answer them, and then perhaps mention your fine newsgroup (as well as
some related alt.learn groups, if it seems appropriate) for future
questions of the same type.

That sounds quite appropriate. Straight C questions can usually be
addressed better in comp.lang.c, so a redirection is good for everyone.
But you should realize that it's not quite the same thing as a Unix
question in comp.lang.c. Many people here don't program for Unix at all,
and we are generally not well-equipped to answer those questions. This
is, of course, the reason we have different groups with different topics
- so that a question can reach those who can best answer it, while not
wasting the time of those who not only cannot answer it, but have no
interest in it.
You guys are like a grumpy neighbor. Kids don't want their ball to get
thrown into his yard by accident, because he won't give it back without
a fight.

This depends very much on the kid. We don't like rude children (who
does?), but we're quite fond of the ones that are respectful and
interested in learning from us.

I actually really like that analogy. It seems very appropriate. That is,
if you consider that the neighbor is grumpy because he's had to deal
with so many rude kids, but he can be quite pleasant as long as you
don't get on his bad side.

-Kevin
 
K

Kevin Goodsell

Bjorn said:
All other groups that I am subscribed to uses a different tactic
to handle off-topic postings; they ignore them. Only comp.lang.c
feels compelled to teach everybody about their charter.

In my experience, people lacking the netiquette skills to post
appropriately also tend to re-post over and over. But more important
than that is the fact that comp.lang.c gets a great number of off-topic
posts. We *have* to actively discourage off-topic posting just to
maintain a reasonable signal-to-noise ratio, and keep the overall
quantity of posts manageable.

If by "everybody" you are referring to the people in other groups, then
I agree. A "that's off-topic here" message isn't appropriate as a
cross-post (and I think it usually only happens by accident). What I was
trying to say is that a message saying "please remove us from the
cross-post list when replying" is appropriate, and to some degree necessary.
As long as comp.lang.c uses their tactic within their own group
I am not going to object, but I have a problem when they
cross-post to other groups, and set the follow-up to all groups
except their own group. Discussions about the charter of
comp.lang.c are topical on comp.lang.c and only there, so the
follow-up should be set to comp.lang.c and not any other group.

I don't think it's expected that discussion will continue to center on
c.l.c's charter[*]. I assume the expectation is that the topic of
discussion will be that of the original post, which does not belong in
c.l.c. As for whether it belongs in the other groups - well, we're not
always able to tell.

That said, I *don't* use the method you are objecting to. I generally
set no follow-ups at all. I figure no one will reply anyway (directly to
my request, that is - and in my experience, this is almost always the
case), so I've never really thought about it. But I also don't think
your suggested alternative is completely appropriate. Actually, I don't
really recognize this as a problem at all, because people usually don't
reply to those messages. All I can say is that I'll keep in mind that
setting the follow-ups for all the other groups may annoy people, and
(continue to) not do it.

[*]Technically, c.l.c has no charter - it predates Usenet charters. But
it does have a specific topic.
The original poster will be educated about the comp.lang.c charter
by the replies that are sent exclusively to comp.lang.c.

Do you really think that inappropriate cross-posters read all the groups
they cross-post to?
Should any replies omit to remove comp.lang.c from the cross-
posting then I am sorry about the noise, but at least you have
the posibility to killfile the thread -- we don't because the
thread, apart from the postings about what is topical on
comp.lang.c, is topical on our groups.

I do not perceive the comp.lang.c charter cross-posting, nor your
refusal to respect the charters of other groups, as good
neighborship.

Please respect the fact that discussions about what is and is not
topical on comp.lang.c are not topical on other groups.

It's certainly not my intent to disrespect any other group's charter,
nor do I believe that that's the intent of the others on comp.lang.c.

I would like 2 things clarified: first, I would like to clarify that
what I am advocating is simply a short, polite message saying something like

This message is not topical in <insert group here>. Please
remove it from the cross-post list when replying. Thank you.

Second, I would like it clarified for me whether this is actually what
others are objecting to. It seems quite reasonable to me, but if it's a
problem for a significant number of people then I will stop doing it and
stop advocating it.

-Kevin
 
B

Barry Margolin

Kevin Goodsell said:
[*]Technically, c.l.c has no charter - it predates Usenet charters. But
it does have a specific topic.

You don't have a written charter, but you obviously have a de facto
charter, or otherwise it wouldn't be so clear to you what's on-topic and
off-topic. Unfortunately, that limited topic is hardly clear from the
name of the group; it's not as if it were "comp.lang.c.portable-only".
So the frequent confusion should be understood.

I used to flame back at the real estate postings in misc.int-property
(they think the name stands for international property rather than
intellectual property). I've given up -- they're spammers and don't
care anyway. Occasionally someone suggests the group be renamed to
avoid the confusion, but it's not a big enough problem to get anyone to
spearhead the effort. If the noise level in comp.lang.c is so high that
you need to be antagonistic, perhaps you should consider something like
this.
 
B

Barry Margolin

Kevin Goodsell said:
I would like 2 things clarified: first, I would like to clarify that
what I am advocating is simply a short, polite message saying something like

This message is not topical in <insert group here>. Please
remove it from the cross-post list when replying. Thank you.

Requests like this are very difficult to follow. Many posters will
reply before ever seeing it (either because they don't read the entire
thread before replying, or because that message hasn't gotten to their
site yet). And you have to remember that a particular thread needs to
be treated specially over the course of several days, and check each
time you follow up to see if the newsgroups have to be filtered.
 
M

Mark McIntyre

On Sun, 07 Dec 2003 08:00:44 GMT, in comp.lang.c , Barry Margolin

(in a long and otherwise dull thread, on the sobject of having flamed
some newby who posted offtopic and didn't read the FAQ or welcome
message)

(ref the nonexistent charter)
We've done this before, ad nauseam. You don't like the rules? Stop
reading posts from clc. You don't like how we respond to offtopic
posts? This is usenet, grow a thicker skin.

(ref renaming the group)
We're happy with it like it is. If you don't like it, killfile
crossposts from clc. The solution is in your hands.
 
G

glen herrmannsfeldt

Barry Margolin wrote:

(snip regarding newsgroup charters)
I used to flame back at the real estate postings in misc.int-property
(they think the name stands for international property rather than
intellectual property). I've given up -- they're spammers and don't
care anyway. Occasionally someone suggests the group be renamed to
avoid the confusion, but it's not a big enough problem to get anyone to
spearhead the effort. If the noise level in comp.lang.c is so high that
you need to be antagonistic, perhaps you should consider something like
this.


It is funny what some groups end up with. comp.sys.powerpc was fine,
until the Power macintosh came out and people would post questions
unrelated to the processor there, just because of the processor.
The fix was to move everything to comp.sys.powerpc.tech, and leave
comp.sys.powerpc alone.

comp.arch also tends to get strange posts, though very rarely posts
about computerized building design.

Oh well.

-- glen
 
A

Alan Balmer

We occasionally get questions in comp.unix.programmer that are about
straight C, with nothing Unix-specific. I've rarely seen anyone here
respond "Sorry, that's not a Unix question, go ask in comp.lang.c." We

That's fine. Go for it, but I think if you reflect on it, you'll see
that the situations are not the same.

Also, please consider that c.l.c has around three time the traffic as
does c.u.p. If we routinely answered off-topic posts, things would
quickly get out of hand.
 
A

Alan Balmer

Discussions about the charter of
comp.lang.c are topical on comp.lang.c and only there, so the
follow-up should be set to comp.lang.c and not any other group.

No. There is no assurance that the offending cross-poster will even
read the reply if it's posted only to c.l.c.
 
C

CBFalconer

Alan said:
No. There is no assurance that the offending cross-poster will
even read the reply if it's posted only to c.l.c.

Which, in turn, is why such a reply should set follow-ups.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,967
Messages
2,570,148
Members
46,694
Latest member
LetaCadwal

Latest Threads

Top