Click here to get back home

sleep/fork/shell/SIGCHLD interaction problem

 HomeNewsGroups | Search | About
 comp.lang.perl.misc    Post an article   get this group's latest topics as an RSS feed add this group's latest topics to your My MSN content add this group's latest topics to your My Yahoo content
Subject Author Date
sleep/fork/shell/SIGCHLD interaction problem Justin Fletcher 11-11-2007
Get Chitika Premium
Posted by Justin Fletcher on November 11, 2007, 10:41 am
Please log in for more thread options
>>
>> [snip]
>>
>> > if I print "$1\n",
>> > the file prints just fine. But, if I do something like print "$1 after
>> > \n", the whole output is messed up. If I print "before $1\n", nothing
>> > prints at all. If I print "before $1 after\n", only after prints.
>>
>> not really sure, but could be a rogue "\r" in $1,


> There
> is a rogue carriage return (0xd) in the string

> Is there something I can do to deal with this
> situation?


Repair the corrupted file:

perl -p -i -e 'tr/\r//d' bad_file


--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas

Posted by Martijn Lievaart on November 11, 2007, 3:40 pm
Please log in for more thread options
>>
>> [snip]
>>
>> > if I print "$1\n",
>> > the file prints just fine. But, if I do something like print "$1 after
>> > \n", the whole output is messed up. If I print "before $1\n", nothing
>> > prints at all. If I print "before $1 after\n", only after prints.
>>
>> not really sure, but could be a rogue "\r" in $1,


> There
> is a rogue carriage return (0xd) in the string

> Is there something I can do to deal with this
> situation?


Repair the corrupted file:

perl -p -i -e 'tr/\r//d' bad_file


--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas

Posted by Ben Morrow on November 11, 2007, 7:21 pm
Please log in for more thread options
>>
>> [snip]
>>
>> > if I print "$1\n",
>> > the file prints just fine. But, if I do something like print "$1 after
>> > \n", the whole output is messed up. If I print "before $1\n", nothing
>> > prints at all. If I print "before $1 after\n", only after prints.
>>
>> not really sure, but could be a rogue "\r" in $1,


> There
> is a rogue carriage return (0xd) in the string

> Is there something I can do to deal with this
> situation?


Repair the corrupted file:

perl -p -i -e 'tr/\r//d' bad_file


--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas

Posted by xhoster on November 11, 2007, 10:30 pm
Please log in for more thread options
>>
>> [snip]
>>
>> > if I print "$1\n",
>> > the file prints just fine. But, if I do something like print "$1 after
>> > \n", the whole output is messed up. If I print "before $1\n", nothing
>> > prints at all. If I print "before $1 after\n", only after prints.
>>
>> not really sure, but could be a rogue "\r" in $1,


> There
> is a rogue carriage return (0xd) in the string

> Is there something I can do to deal with this
> situation?


Repair the corrupted file:

perl -p -i -e 'tr/\r//d' bad_file


--
Tad McClellan SGML consulting
tadmc@augustmail.com Perl programming
Fort Worth, Texas

Posted by Ben Morrow on November 12, 2007, 9:34 am
Please log in for more thread options

Quoth xhoster@gmail.com:
> >
> > I'm having a problem trying to get a simple program to respond the way
> > that I expect. The basic premise is thus :
> >
> > 1. Fork a child.
> > 2. Sleep for a while.
> > 3. Do other stuff.
> >
> > This seems pretty simple, and I have a SIGCHLD handler which will catch
> > my forked process if it exits. I thought everything was fine. Then I
> > found that is I press ctrl-Z to suspend the parent whilst I'm running the
> > program and then background it, it hangs.
>
> I find that this only occurs if I hit ctrl-Z from the keyboard. If I
> send the process the TSTP signal via some other means, it doesn't happen.
> I know that shells often respond to ctrl-Z, ctrl-C, etc, by sending signals
> to entire process groups, rather than just the main process. I don't
> exactly how this leads to the observed phenomena, though.

SIGCHLD is sent to the parent whenever a child changes status. So when
you press ctrl-Z, the whole process group is signalled, the child is
stopped, and the parent gets a SIGCHLD. When the process group is
resumed (bg or fg) the parent gets another SIGCHLD: since it hasn't
responded to the first yet (because it was stopped), this is not
usually apparent.

If the OP really doesn't want SIGCHLDs when a child stops, he can
install the signal handler explicitly with sigaction and SA_NOCLDSTOP
(under systems which support that). Since one must assume that any
number of children may have exitted when handling SIGCHLD anyway,
including 0 in 'any number' is generally easier.

Ben


Similar ThreadsPosted
Perl <-> C language interaction August 23, 2005, 8:50 pm
JavaScript for User interaction. April 28, 2006, 7:45 am
Google calendar interaction October 8, 2006, 12:49 am
Perl interaction with Expect February 14, 2007, 3:54 pm
Problem installing modules on redhat 9 - strange connection problem January 26, 2005, 5:19 am
ReFresh problem or target problem September 14, 2005, 9:23 pm
Is it a gtk2 problem or Threads problem March 18, 2006, 11:28 pm
CGI PROBLEM October 2, 2004, 12:51 am
tr problem September 30, 2004, 10:13 am
problem with LWS February 3, 2005, 12:55 am

Our other projects:

Art Dolls, Fairies and Mermaids - Sunnyfaces.net

Roy's Linux, Programming and Search Engines messages

1-Script XML SitemapXML Sitemap