tags:

views:

46

answers:

3

Hello all,

i wanna know how does cp command gets executed , i mean its flow from top most layer to kernel and back again? what is its flow , what happend when we write cp command and how it happens? please tell it in detail.

@ all its reallu urgent for me to know this , so please reply ASAP

thanks in advance,

newbie

A: 

Hello, you could probably download the sources. If you have some debian:

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

I would suggest you do a strace on a cp command like:

$ strace cp foo bar

This way you'll see all the system calls made by the cp command.

codaddict
A: 

foo.c contents before cp:

this is foo

strace cp foo.c bar.c gave me this:

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)                           = ?
Kedar Soparkar