I have written a C++ program and complied it to produce a.out file. However, whenever I try to run it, I get Permission Denied. I read that we can use sudo, but I can't quite get it to work. I use something like, sudo "./a.out" but that too doesn't work.
Edit:
Here is the message I get when I try "./a.out".
bash: ./a.out: Permission denied
Best Answer
Usually,
g++
gives the created file execute permissions. If you do not pass the-o
option, the file will be nameda.out
.Two possible reasons why your file does not have the execute bit set, with their solutions:
The umask value is set to a value like 0133, thereby preventing the execute bit from being set. Solution: set the permissions explicitly:
fmask=0022
orumask=0022
(omittingfmask
). See the Mount options for fat section on the manual page of mount for more details.For bash scripts which do not have the execute bit set, you could run
bash file.sh
. Such a feature exists for all files with executable content (compiled files and files with a shebang line#!/path/to/interpreter
set). To execute files without the execute bit set, use the special file/lib/ld-linux.so.2
(or/lib/ld-linux-x86-64.so.2
for 64-bit applications) to run such a program: