-   Programming (
-   -   can't execute c++ binaries, "permission denied"... even though permission is 777 (

SerfurJ 10-11-2003 11:32 PM

can't execute c++ binaries, "permission denied"... even though permission is 777
i'm having trouble executing simple c++ binaries. bash returns a permission denied error, even though i set the file's permissions to 777. i'm using g++ compiler on RH9. for some reason it works on my laptop, also RH9. does it have something to do with installed c++ libraries? any suggestions on how to fix it?


mr_segfault 10-12-2003 02:59 AM

I think we would need a little more info than you have provided to determine what is going wrong..

Can you paste the command you entered, the error output and anything else that might help us determine what's going on.

It is possible that your binary is attempting to load a shared object for which you dont have read permissions..

If you are not getting much info on what is going bad, you can do an strace on your binary to see if it is something like that.


strace -e trace=file <your_executable>
This will allow you to see all system calls to file routines and see if it is your binary accessing something or not, also you will see what it failed to open.


BigFred 10-12-2003 08:22 AM

Hi SerfurJ

Who ownes the directory where the executable will end up? Perhaps it needs 777 also. And if you are trying to execute from the current directory, is it in the path. BF

SerfurJ 10-13-2003 05:48 PM

i don't get much info. here's what i enter along with the output:

$ ./hello-test
bash: ./hello-test: Permission denied


$ bash hello-test
hello-test: hello-test: cannot execute binary file

trying what you suggested:

$strace -e trace=file ./hello-test
strace: exec: Permission denied
execve("./hello-test", ["./hello-test"], [/* 53 vars */]) = 0

i'm not sure what to make of that.

big fred,
i tried that... no banana. i'm using "./" in front of the binary, so it doesn't have to be in the path.

any more ideas? how could i find out if i don't have read permissions for a shared object?


mr_segfault 10-13-2003 05:52 PM

It looks like you may not have permission to run/call exec.. I'll do some testing and get back to you..


bastard23 10-14-2003 03:59 PM


Is your filesystem mounted with the noexec option? "grep -i exec /etc/fstab" or "mount|grep -i exec". Have you configured any of the Access control systems. (I don't know what Redhat includes).

Can you run a shell script (or simple c program) from this directory. It may not be related to c++ at all.

Good Luck,

SerfurJ 10-14-2003 09:01 PM

hey good suggestions chris. the drive where i am running these binaries is separate from my linux installation drive, so that seemed like a pretty good explanation. unfortunately, that wasn't it. here's the entry for the drive where it's running from:

/dev/hdh1 /home/jason/mydocs ext3 defaults,user 1 1

i've never heard of any "access control systems" in redhat. is this a gui configurator in debian?

i tried copying the cat binary to the directory that i'm trying to run the c++ binaries from. here's the input/output:

bash: ./cat: Permission denied

it's funny that perl scripts run from this drive. i think we're on to something. i copied the c++ binary to my other drive and it worked. so what else would keep binaries from running on a mounted filesystem?

megaspaz 10-14-2003 09:27 PM

can you try to change that fstab entry to something like this?

/dev/hdh1 /home/jason/mydocs ext3 defaults,user,exec 1 1

i guess you'll have to log out and log in as root so you can unmount it and remount it.

bastard23 10-14-2003 10:09 PM

This option implies the options noexec, nosuid, and nodev (unless overridden by subsequent options, as in the option line user,exec,dev,suid). Quothe the mount man page on the user option. Makes sense, I guess.

SerfurJ 10-17-2003 08:26 AM

i just removed the user option and that fixed it. thanks a lot bastard23 et al. for the help.

gengiskanhg 01-23-2007 07:31 PM

Thanks very much GNU brothers
I am new in ubuntu with two years of GNU experience. GNU systems like linux are marvelous and you, the community too. Thanks for your help. The solution and the process to diagnosticate the problem help me too. Thanks. Adding "Mount" option "exec" is the key... eh ;-)
$more /etc/fstab | grep exec
/dev/hda9 /home/user/docs ext3 defaults,user,exec 0 2 05-28-2008 02:57 PM

Thank you very much -- had the same problem here. This was pretty difficult to track down...

Sanchi 02-19-2009 04:48 AM

problem in getting output
I am new to ubuntu. was writing a cpp program in vi editor(i suppose d editor is not dat important though), but as i put the command for output, it said permission denied... i tried out crtain things that i am pasting here.. even that didnot work.. I have no ida whatsoever

sanchita@sanchita-desktop:~$ ./unary_op_overload.cpp
bash: ./unary_op_overload.cpp: Permission denied
sanchita@sanchita-desktop:~$ strace -e trace=file./unary_op_overload.cpp
strace: invalid system call `file./unary_op_overload.cpp'
sanchita@sanchita-desktop:~$ strace -e trace=file ./unary_op_overload.cpp
execve("./unary_op_overload.cpp", ["./unary_op_overload.cpp"], [/* 36 vars */]) = -1 EACCES (Permission denied)
strace: exec: Permission denied
Process 7807 detached
sanchita@sanchita-desktop:~$ grep -i exec /etc/fstab
/dev/scd0 /media/cdrom0 udf,iso9660 user,noauto,exec,utf8 0 0

dwhitney67 02-19-2009 06:58 AM


You need to compile/link your application before you can run it. Maybe you already have?


g++ unary_op_overload.cpp -o unary_op_overload

Note the when running the program, the .cpp extension is not used.

P.S. The -o option instructs the GCC (g++) linker what to name the executable program. Change the name to something else if you wish. If you do not specify the -o option, the executable program will be named a.out.

Sanchi 02-20-2009 04:50 AM


thanks for the post... it worked!
wel i had compiled it earlier and then executed ofcourse. wel couldnot understand 1 little part in dis... i had tried ./a.out as well. and if -o is not utilized, ./a.out should give the result, which didnot occur so.. can you please explain me this?
thanks anyway, it worked.

All times are GMT -5. The time now is 05:31 PM.