In my linux machine if i try to copy /proc/stat it is creating 0 byte file. but if i do cat /proc/stat it has data. but the size always shows as 0.
cp /proc/stat statfile
is creating zero byte file. If i write a program to copy then it worked. why is it so ?
int main()
{
std::ifstream procFile("/proc/stat");
std::ofstream outfile("statfile");
char buf[1024];
while (!procFile.eof() && procFile.is_open())
{
procFile.getline(buf, 1024);
outfile << buf<<endl;
}
procFile.close();
outfile.close();
return 0;
}
This means cp: cannot stat 'mock/*': No such file or directory unable to copy all files from mock folder because file or directory not exists on relevant path. Follow this answer to receive notifications.
The Linux /proc File System is a virtual filesystem that exists in RAM (i.e., it is not stored on the hard drive). That means that it exists only when the computer is turned on and running.
In test environment, this file refreshed 1 ~ 2 sec, so I assume this file often updated by system at least 1 sec. But, In commercial servers environment, process run with high load (cpu and file IO), /proc/[pid]/stat file update period increasing even 20~60 sec!!
/proc – This is a virtual file system used to provide information about the system. For each file there is a corresponding set of functions that are called in the kernel. A device driver can install a handler for a particular file name in the /proc folder.
/proc
is a pseudo-filesystem. It indicates a size of 0 for the file /proc/stat
.
This is why copying doesn't work (cp does first look at the size of the file it has to copy), but you can easily read the information and write it back to a file.
$> cat /proc/stat > statfile
This was fixed in GNU coreutils 7.3.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With