LinuxQuestions.org
Review your favorite Linux distribution.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 11-23-2023, 12:58 AM   #16
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,976

Rep: Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337

I just can't reproduce it using an old centos with gawk 4.0.2 and suse with 3 different gawk (4.x 5.1). I don't really know.
From the other hand in case of a sigpipe how do you know if [g]awk | head is broken or cmd | getline is broken, which one caused the signal?
 
Old 11-23-2023, 03:18 AM   #17
ychaouche
Member
 
Registered: Mar 2017
Distribution: Mint, Debian, Q4OS, Mageia, KDE Neon
Posts: 369

Original Poster
Blog Entries: 1

Rep: Reputation: 49
This is interesting,
thank you all for your input.
So since pan64 can't reproduce it in gawk4 and gawk5.1,
could it have something to do with coreutils maybe?
 
Old 11-23-2023, 05:06 AM   #18
MadeInGermany
Senior Member
 
Registered: Dec 2011
Location: Simplicity
Posts: 2,816

Rep: Reputation: 1211Reputation: 1211Reputation: 1211Reputation: 1211Reputation: 1211Reputation: 1211Reputation: 1211Reputation: 1211Reputation: 1211
I think it is a bug in gawk. Happens in combination with | getline and close() and SIGPIPE on its stdout.

A workaround: avoid the SIGPIPE on stdout.
Code:
printf %s\\n {1..20} | awk '{cmd="sleep 1; echo howody?"; cmd | getline x; close(cmd); print x; if (++n == 2) exit}'; echo done
 
Old 11-23-2023, 05:11 AM   #19
ychaouche
Member
 
Registered: Mar 2017
Distribution: Mint, Debian, Q4OS, Mageia, KDE Neon
Posts: 369

Original Poster
Blog Entries: 1

Rep: Reputation: 49
Thanks for the workaround @MadeInGermany,
however the goal is to have the (original) awk script unchanged,
and process its output by piping it to other utilities the unix way.
 
Old 11-23-2023, 05:39 AM   #20
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,976

Rep: Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337Reputation: 7337
you might collect all the output into a file and run head on that file. It is probably not that efficient, but at least should work.
Probably it depends on the version of bash too, it is the shell which must somehow manage the pipe(s) and the sigpipe signal.
 
1 members found this post helpful.
  


Reply

Tags
awk, pipe, signal



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Sed a piped awk isuuck Linux - Newbie 9 10-18-2015 01:04 PM
[SOLVED] Using a variable with Piped AWK commands ampsys Programming 4 01-24-2014 06:15 PM
Not terminating bash script TheIrish Programming 1 11-12-2008 11:36 PM
Start a script after GDM autologin, don't quit when script finishes Plastech Linux - Newbie 2 05-29-2007 10:15 AM
PHP Shell Script - Read piped text dlublink Linux - Software 3 08-13-2005 01:57 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:38 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration