Live Chat & Podcast at 1:00PM Eastern on Sunday!
There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
Search
Linux and Unix
Tag Cloud
access acer asus bios bsod computer crash driver drivers error ethernet excel freeze gaming gpu hard drive hardware hdmi internet laptop mac malware memory monitor motherboard music network printer problem ram registry router server slow software sound trojan ubuntu 11.10 uninstall usb video virus vista wifi windows windows 7 windows 7 32 bit windows 7 64 bit windows xp wireless
Search
Search for:
Tech Support Guy Forums > Operating Systems > Linux and Unix >
Solved: ..... strace and a pipe

Reply  
Thread Tools
klam's Avatar
Senior Member with 181 posts.
 
Join Date: Apr 2006
Experience: Advanced
20-Sep-2006, 08:02 PM #1
Solved: ..... strace and a pipe
OK so I wanted to know how does grep outputs to the pipe and how sort reads from it. So I run a strace over "grep blah myfile | sort" and this is what I got:

open("myfile", O_RDONLY|O_LARGEFILE) = 3
fstat64(3, {st_mode=S_IFREG|0600, st_size=84, ...}) = 0
read(3, "blah blah and blah cause of blah"..., 32768) = 84
fstat64(1, {st_mode=S_IFIFO|0600, st_size=0, ...}) = 0
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb7fe8000
read(3, "", 32768) = 0
close(3) = 0
write(1, "blah blah and blah cause of blah"..., 85) = 85
close(1) = 0
munmap(0xb7fe8000, 4096) = 0
exit_group(0) = ?
Process 14533 detached
blah blah and blah cause of blah
find blah myfile blah grep it.
this is my blah file

Obviously grep nor sort are aware of the pipe they just input/output to the stdin/stdout... the pipe just connect them. But what I don't see in this code is how grep is outputing to the pipe (stdout) and how is sort reading from the pipe (stdin). Is there anyway to check that realtion? All I can tell from the code I bolded is:

MyFile -> Grep --------------------------> stdout

Unless "read(3, "", 32768)" has anything to do with the sort process.
Thanks in advance.
__________________
"the only refuge from the damnation of the panta rei, and she guessed it was the Pendulum’s business, not hers"
O111111O's Avatar
Computer Specs
Senior Member with 896 posts.
 
Join Date: Aug 2005
Location: Right here.
Experience: 31337
22-Sep-2006, 11:10 PM #2
Here you go, it's a great story. In my mind, one of the most elegant innovations for computing ever.

http://www.softpanorama.org/Scripting/pipes.shtml
klam's Avatar
Senior Member with 181 posts.
 
Join Date: Apr 2006
Experience: Advanced
23-Sep-2006, 04:02 PM #3
Not quite what I was looking for but thanks anyways...
AGCurry's Avatar
Senior Member with 431 posts.
 
Join Date: Jun 2005
Location: Kansas City area
Experience: advanced but learning
25-Sep-2006, 09:55 AM #4
Quote:
Originally Posted by klam

open("myfile", O_RDONLY|O_LARGEFILE) = 3

fstat64(3, {st_mode=S_IFREG|0600, st_size=84, ...}) = 0
read(3, "blah blah and blah cause of blah"..., 32768) = 84
fstat64(1, {st_mode=S_IFIFO|0600, st_size=0, ...}) = 0
mmap2(NULL, 4096, PROT_READ|PROT_WRITE, MAP_PRIVATE|MAP_ANONYMOUS, -1, 0) = 0xb7fe8000
read(3, "", 32768) = 0
close(3) = 0
write(1, "blah blah and blah cause of blah"..., 85) = 85
close(1) = 0
munmap(0xb7fe8000, 4096) = 0
exit_group(0) = ?
Process 14533 detached
blah blah and blah cause of blah
find blah myfile blah grep it.
this is my blah file

Unless "read(3, "", 32768)" has anything to do with the sort process.
Thanks in advance.
No, "read( 3, ...)" is from grep. File descriptor 3 is input from myfile. Sort is not telling you anything about itself, but grep is telling you a little and the "|" is telling you quite a bit.

File descriptor 1 is stdout. fstat64 checks on the status of stdout; then, mmap2 maps an area of memory to stdout. That's how the pipe is working - as a memory map, which sort reads from.
Reply

THIS THREAD HAS EXPIRED.
Are you having the same problem? We have volunteers ready to answer your question, but first you'll have to join for free. Need help getting started? Check out our Welcome Guide.

Search Tech Support Guy

Find the solution to your
computer problem!




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
WELCOME TO TECH SUPPORT GUY! Are you looking for the solution to your computer problem? Join our site today to ask your question -- for free! Our site is run completely by volunteers who want to help you solve your computer problems. See our Welcome Guide to get started.
Thread Tools



Facebook Facebook Twitter Twitter TechGuy.tv TechGuy.tv Mobile TSG Mobile
You Are Using:
Server ID
Advertisements do not imply our endorsement of that product or service.
All times are GMT -4. The time now is 05:22 PM.
Copyright © 1996 - 2011 TechGuy, Inc. All rights reserved.

Powered by Cermak Technologies, Inc.