There's no such thing as a stupid question, but they're the easiest to answer.
JoinTour
Login
 
Tag Cloud
access audio avg avg 8 bios blue screen boot bsod computer connection cpu crash css dell desktop dma driver drivers dvd email error excel explorer firefox firefox 3 freeze gimp graphics hard drive hardware hijackthis hjt install internet internet explorer itunes keyboard laptop macro malware monitor motherboard network networking outlook outlook 2003 outlook 2007 outlook express pio problem problems router seo server slow sound sp3 spyware trojan usb video virtumonde virus vista vundo windows windows vista windows xp winxp wireless
UNIX/Linux
Search
Search in:
 
Advanced Search
Tech Support Guy Forums > Operating Systems > UNIX/Linux >
Solved: ..... strace and a pipe


HELLO AND WELCOME! Before you can post your question, you'll have to register -- it's completely free! Click here to join today! We highly recommend that you print a copy of our Guide for New Members. Enjoy!

 
Thread Tools
klam's Avatar
Senior Member with 181 posts.
 
Join Date: Apr 2006
Experience: Advanced
20-Sep-2006, 07: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 893 posts.
 
Join Date: Aug 2005
Location: Right here.
Experience: 31337
22-Sep-2006, 10: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, 03: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, 08: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


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

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 On
HTML code is Off
Trackbacks are On
Pingbacks are Off
Refbacks are Off

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:00 AM.
Copyright © 1996 - 2008 TechGuy, Inc. All rights reserved.
Powered by vBulletin, Copyright © 2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Powered by Cermak Technologies, Inc.