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?
Best Answer
The two processes are
sudo
on the one hand, andcp
on the other. When you runthe shell starts
sudo
with the full command line; thensudo
(which runs asroot
because it is setuidroot
) checks that you're allowed to runcp
like that, and forks and startscp
. So whilecp
is running you see bothsudo
andcp
processes.