7

I am trying to copy some files and folders on a CentOS machine.

I do it like so: sudo cp source destination & to run it in the background.

I see there are three cp processes now when I run ps aux | grep cp: One of them is the grep command itself, but the other two are copies of the above cp command: one with the entire command listed above and the other without the sudo in front. The PIDs of the two processes also differs by one. The owner of both is listed as root.

Why are there two processes?

1
  • You already understand why grep cp shows up in the process list. This should explain why sudo cp also shows up.
    – Kusalananda
    Mar 7, 2021 at 8:52

1 Answer 1

15

The two processes are sudo on the one hand, and cp on the other. When you run

sudo cp source destination &

the shell starts sudo with the full command line; then sudo (which runs as root because it is setuid root) checks that you're allowed to run cp like that, and forks and starts cp. So while cp is running you see both sudo and cp processes.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .