I'm trying to understand how cp command is similar to/different from a read/write combination in terms of context switches. In other words, is using cp to copy data from within application equivalent to using read/write combination. I think read/write combination does 4 context swiches - user context - kernel context (data copied to kernel buffer, then data copied to user space) - user context, for reading, and then another set of 2 context switches for write. How many context switches would happen for cp? Also would zero-copy or sendfile be better than using cp?
I'm on linux platform and using kernel later than 2.4.
Thanks.