【问题标题】:flowchart of "cp" command in linux [closed]linux中“cp”命令的流程图[关闭]
【发布时间】:2010-09-24 07:19:01
【问题描述】:

我想知道cp 命令是如何执行的。我的意思是它从最顶层到内核再返回?它的流量是多少?当我们编写cp 命令时会发生什么以及它是如何发生的?请详细说一下。

【问题讨论】:

  • 说我想尽快得到答案是不礼貌的。

标签: linux


【解决方案1】:

foo.c cp前的内容:

this is foo

strace cp foo.c bar.c 给了我这个:

execve("/bin/cp", ["cp", "foo.c", "bar.c"], [/* 58 vars */]) = 0

//several calls to open, fstat64, mmap2, close

open("foo.c", O_RDONLY|O_LARGEFILE)     = 3
    fstat64(3, {st_mode=S_IFREG|0664, st_size=12, ...}) = 0

    open("bar.c", O_WRONLY|O_CREAT|O_EXCL|O_LARGEFILE, 0664) = 4
        fstat64(4, {st_mode=S_IFREG|0664, st_size=0, ...}) = 0
        read(3, "this is foo\n", 32768)         = 12
        write(4, "this is foo\n", 12)           = 12
        read(3, "", 32768)                      = 0
    close(4)                                = 0
close(3)                                = 0

close(0)                                = 0  // close stdin
close(1)                                = 0  // close stdout
close(2)                                = 0  // close stderr
exit_group(0)                           = ?

【讨论】:

    【解决方案2】:

    我建议您对 cp 命令执行 strace,例如:

    $ strace cp foo bar
    

    这样您将看到由cp 命令生成的所有system calls

    【讨论】:

      【解决方案3】:

      您可能可以下载源代码。如果你有一些 debian:

      #this will tell you what package cp comes from
      dpkg -S "$(which cp)"
      apt-get source the_package_name_here
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2014-09-26
        • 2012-09-13
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-12-05
        相关资源
        最近更新 更多