In order to clear caches, I usually invoke
# echo 3 | tee /proc/sys/vm/drop_caches
This requires root privileges. Why do I need to do this occasionally? Because it can have a huge impact on the runtime of some of my programs. My question is: how can I do this without superuser privileges, in particular these 2 circumstances:
1) I/the user does not have root privileges. Can the system administrator do anything to allow normal users run the command above?
2) The calls to drop caches are from within a shell script, and running the whole script with superuser privileges is not an option. For example because there are multiple instances of calling "mpirun" within this script, which really should not be run as root. And running everything within the script as root, although only a few lines actually need it, does not seem like good practice to me.
edit: forgot to mention: above command only works while being logged in as root. Otherwise the command would be echo 3 | sudo tee /proc/sys/vm/drop_caches
touch /tmp/clear_cache
, issue the command and remove the file. Be careful with that script to avoid security problems.sudoers
file to allow all users to execute your script with root permissions. For bonus points have the script call itself withsudo
if it's not already running as the root user.