How to use strace upon redirection?

Tian, Kevin kevin.tian at intel.com
Thu Aug 7 00:13:01 UTC 2003


Roland McGrath wrote:
> -----Original Message-----
> From: Roland McGrath [mailto:roland at redhat.com]
> Sent: 2003年8月7日 14:55
> To: Tian, Kevin
> Cc: strace-devel at lists.sourceforge.net
> Subject: Re: How to use strace upon redirection?
> 
> > I'd like to use strace to see what shell will do for redirection.
> > However it seems hard to achieve it.
> >
> > For example: "#strace cat /etc/passwd >aaa"
> >
> > Shell will make the redirection before execve "strace cat /etc/passwd"
> > and ">aaa" is considered as parameter to shell, not to cat.
> 
> Perhaps by reading strace output you will learn how redirection really
> works, which is not by passing strings such as ">aaa" to execve.
> 
> Try:
> 	$ strace sh -c 'cat /etc/passwd > aaa'

Thanks, Roland. '' is just what I want. To do as what you suggest, I got:
[Cut some data]
...
Open("aaa"...) = 3
Dup2(3, 1) = 1
Close(3) = 0
Execve("/bin/cat", ...) = 0
...

So the redirection occurs before execve. Strace is really powerful enough. :)

-Kevin




More information about the Strace-devel mailing list