简体   繁体   中英

ls command required system calls compared to ls -l?

So basically I have an assignment to analyze using strace, which system calls are required for the ls command to give the same information as ls -l.

But there are many odd system calls for the ls -l command, for example stat 64 being called with /etc/localtime as parameter for every file? Example(this is being repeated for every file in current dir):

stat64( "/etc/localtime", {st_mode=S_IFREG|0644,
st_size=1892, ...}) = 0
write(1, "-rwxrwxr-x 1 john john 10441"..., 55-rwxrwxr-x
1 john john 10441 jan 1 14:39 stattest
) = 55
stat64( "/etc/localtime", {st_mode=S_IFREG|0644,
st_size=1892, ...}) = 0
write(1, "-rw-rw-r-- 1 john john 320"..., 57-rw-rw-r--
1 john john 320 jan 1 14:39 stattest.c
) = 57

Why is stat64 being called with localtime as parameter for every file? seems a bit odd. Shouldn't all the relevant file information be obtainable by a stat call though? why does ls -l need to use lstat and so many other different weird calls, socket connections etc.

Could someone help me figure out what the essential system calls to actually get the relevant information missing from the command ls, that is given by ls -l ?

Thanks!

The stat64 calls are likely invoked by some libc function to convert file times to your local timezone. Since the function call doesn't keep the timezone information around behind the scenes (what if a program changed the timezone halfway through execution?), it happens every time that call is invoked.

If you want to find out what function in particular is doing it, use gdb to catch the syscall and look at the stack trace (see the GDB documentation on catch syscall for details).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM