Cannot execute my own programs

Hi
It is a bit strange but I can’t execute the programs I wrote.
This is the code:


alex@suse:~/Desktop> cat HelloWorld.c
#include<stdlib.h>
#include<stdio.h>

int main(){
        printf("Hello World!");
        exit(EXIT_SUCCESS);
}

I can compile it:


alex@suse:~/Desktop> !gcc
gcc -Wall -pedantic -g ./HelloWorld.c -o HelloWorld

The permission bits look ok:


alex@suse:~/Desktop> ll
total 20
-rwxr-xr-x 1 alex users 10499 Apr 26 14:16 HelloWorld
-rw-r--r-- 1 alex users    98 Apr 26 14:10 HelloWorld.c

But I can’ execute it:


alex@suse:~/Desktop> ./HelloWorld
bash: ./HelloWorld: Permission denied

alex@suse:~/Desktop> exec ./HelloWorld
bash: /home/alex/Desktop/HelloWorld: Permission denied
bash: exec: /home/alex/Desktop/HelloWorld: cannot execute: Permission denied

I also tried to execute it as root, the output is the same.

Maybe one or more of the bash flags are set incorrectly?

alex@suse:~/Desktop> set -o
allexport       off
braceexpand     on
emacs           on
errexit         off
errtrace        off
functrace       off
hashall         on
histexpand      on
history         on
ignoreeof       off
interactive-comments    on
keyword         off
monitor         on
noclobber       off
noexec          off
noglob          off
nolog           off
notify          off
nounset         off
onecmd          off
physical        off
pipefail        off
posix           off
privileged      off
verbose         off
vi              off
xtrace          off
alex@suse:~/Desktop> set +o
set +o allexport
set -o braceexpand
set -o emacs
set +o errexit
set +o errtrace
set +o functrace
set -o hashall
set -o histexpand
set -o history
set +o ignoreeof
set -o interactive-comments
set +o keyword
set -o monitor
set +o noclobber
set +o noexec
set +o noglob
set +o nolog
set +o notify
set +o nounset
set +o onecmd
set +o physical
set +o pipefail
set +o posix
set +o privileged
set +o verbose
set +o vi
set +o xtrace

Is your /home on an external disk, mounted on demand or a network mount? Do:

mount

and paste the output here. You may have this filesystem mounted noexec (explicitly or implicitly due to other mount options, e.g. user).

It could be possible that your home folder is mounted with noexec option. What is the output of the


mount

command?


alex@suse:~> mount
devtmpfs on /dev type devtmpfs (rw,relatime,size=2034100k,nr_inodes=204392,mode=755)
tmpfs on /dev/shm type tmpfs (rw,relatime)
devpts on /dev/pts type devpts (rw,relatime,gid=5,mode=620,ptmxmode=000)
/dev/sda6 on / type ext4 (rw,relatime,user_xattr,acl,barrier=1,nodelalloc,data=journal)
proc on /proc type proc (rw,relatime)
sysfs on /sys type sysfs (rw,relatime)
debugfs on /sys/kernel/debug type debugfs (rw,relatime)
/dev/sda5 on /boot type ext4 (rw,relatime,user_xattr,acl,barrier=1,nodelalloc,data=journal)
/dev/sda7 on /home type ext4 (rw,nosuid,nodev,noexec,relatime,user_xattr,acl,barrier=1,data=ordered)
fusectl on /sys/fs/fuse/connections type fusectl (rw,relatime)
/dev/sdb2 on /mnt/backup type fuseblk (rw,nosuid,nodev,noexec,relatime,user_id=0,group_id=0,default_permissions,allow_other,blksize=4096)
/dev/sdb6 on /mnt/ubuntu type ext4 (rw,nosuid,nodev,noexec,relatime,acl,barrier=1,data=ordered)
/dev/sdb7 on /mnt/ubuntu/home type ext4 (rw,nosuid,nodev,noexec,relatime,acl,barrier=1,data=ordered)
/dev/sdb4 on /mnt/windows7 type fuseblk (rw,nosuid,nodev,noexec,relatime,user_id=0,group_id=0,default_permissions,allow_other,blksize=4096)
securityfs on /sys/kernel/security type securityfs (rw,relatime)
gvfs-fuse-daemon on /home/alex/.gvfs type fuse.gvfs-fuse-daemon (rw,nosuid,nodev,relatime,user_id=1000,group_id=100)

Your home folder is being mounted with the noexec permission. What is the output of:


cat /etc/fstab

?


alex@suse:~> cat /etc/fstab
UUID=174480e6-309c-42c7-a66a-248b9284426a /                    ext4       data=journal,acl,user_xattr 1 1
UUID=54b41216-7efe-498e-a19b-d914381c1f57 /boot                ext4       data=journal,acl,user_xattr 1 2
UUID=6330890b-3b27-4ad8-997a-80a1dac065b4 /home                ext4       user,acl,user_xattr   1 2
/dev/disk/by-id/ata-WDC_WD5000AAKS-00YGA0_WD-WCAS84837814-part5 swap                 swap       defaults              0 0
proc                 /proc                proc       defaults              0 0
sysfs                /sys                 sysfs      noauto                0 0
debugfs              /sys/kernel/debug    debugfs    noauto                0 0
usbfs                /proc/bus/usb        usbfs      noauto                0 0
devpts               /dev/pts             devpts     mode=0620,gid=5       0 0
/dev/disk/by-id/ata-WDC_WD5000AAKS-00YGA0_WD-WCAS84837814-part2 /mnt/backup          ntfs-3g    user,users,gid=users,fmask=133,dmask=022,locale=en_US.UTF-8 0 0
/dev/disk/by-id/ata-WDC_WD5000AAKS-00YGA0_WD-WCAS84837814-part6 /mnt/ubuntu          ext4       user,acl              1 2
/dev/disk/by-id/ata-WDC_WD5000AAKS-00YGA0_WD-WCAS84837814-part7 /mnt/ubuntu/home     ext4       user,acl              1 2
/dev/disk/by-id/ata-WDC_WD5000AAKS-00YGA0_WD-WCAS84837814-part4 /mnt/windows7        ntfs-3g    user,users,gid=users,fmask=133,dmask=022,locale=en_US.UTF-8 0 0

Try changing this line:


UUID=6330890b-3b27-4ad8-997a-80a1dac065b4 /home                ext4       user,acl,user_xattr   1 2

to this:


UUID=6330890b-3b27-4ad8-997a-80a1dac065b4 /home                ext4       user,acl,user_xattr,**exec**   1 2

Notice the exec option. That should allow you run run executables on the /home partition. Then restart.

Or just remove the “user” option since it looks like a non-removable disk and there is no need for users to be able to initiate a mount, it will be mounted at boot time.


alex@suse:~/Desktop> mount
devtmpfs on /dev type devtmpfs (rw,relatime,size=2034100k,nr_inodes=204392,mode=755)
tmpfs on /dev/shm type tmpfs (rw,relatime)
devpts on /dev/pts type devpts (rw,relatime,gid=5,mode=620,ptmxmode=000)
/dev/sda6 on / type ext4 (rw,relatime,user_xattr,acl,barrier=1,nodelalloc,data=journal)
proc on /proc type proc (rw,relatime)
sysfs on /sys type sysfs (rw,relatime)
debugfs on /sys/kernel/debug type debugfs (rw,relatime)
/dev/sda5 on /boot type ext4 (rw,relatime,user_xattr,acl,barrier=1,nodelalloc,data=journal)
**/dev/sda7 on /home type ext4 (rw,nosuid,nodev,relatime,user_xattr,acl,barrier=1,data=ordered)**
fusectl on /sys/fs/fuse/connections type fusectl (rw,relatime)
/dev/sdb2 on /mnt/backup type fuseblk (rw,nosuid,nodev,noexec,relatime,user_id=0,group_id=0,default_permissions,allow_other,blksize=4096)
/dev/sdb6 on /mnt/ubuntu type ext4 (rw,nosuid,nodev,noexec,relatime,acl,barrier=1,data=ordered)
/dev/sdb7 on /mnt/ubuntu/home type ext4 (rw,nosuid,nodev,noexec,relatime,acl,barrier=1,data=ordered)
/dev/sdb4 on /mnt/windows7 type fuseblk (rw,nosuid,nodev,noexec,relatime,user_id=0,group_id=0,default_permissions,allow_other,blksize=4096)
securityfs on /sys/kernel/security type securityfs (rw,relatime)
gvfs-fuse-daemon on /home/alex/.gvfs type fuse.gvfs-fuse-daemon (rw,nosuid,nodev,relatime,user_id=1000,group_id=100)

It works now! :smiley:


alex@suse:~/Desktop> ./HelloWorld 
Hello World!

Thank you

You try to run a program in terminal-a C program.
I want to give you some ideas. I like to see people to develop with terminal.
Try to run programs in Kwrite first or in Compiler DevC/C++

I speak about this program

alex@suse:~/Desktop> cat HelloWorld.c
#include<stdlib.h>
#include<stdio.h>

int main(){
        printf("Hello World!");
        exit(EXIT_SUCCESS);
}

That was my first program when I start object oriented programming.

You’re welcome :slight_smile:

Yes, they’re all non-removable
I removed the “user” option from all the entries now, otherwise I had the same problem with other disks.


alex@suse:~/Desktop> ./HelloWorld 
Hello World!alex@suse:~/Desktop> cat /etc/fstab
UUID=174480e6-309c-42c7-a66a-248b9284426a /                    ext4       data=journal,acl,user_xattr 1 1
UUID=54b41216-7efe-498e-a19b-d914381c1f57 /boot                ext4       data=journal,acl,user_xattr 1 2
UUID=6330890b-3b27-4ad8-997a-80a1dac065b4 /home                ext4       acl,user_xattr   1 2
/dev/disk/by-id/ata-WDC_WD5000AAKS-00YGA0_WD-WCAS84837814-part5 swap                 swap       defaults              0 0
proc                 /proc                proc       defaults              0 0
sysfs                /sys                 sysfs      noauto                0 0
debugfs              /sys/kernel/debug    debugfs    noauto                0 0
usbfs                /proc/bus/usb        usbfs      noauto                0 0
devpts               /dev/pts             devpts     mode=0620,gid=5       0 0
/dev/disk/by-id/ata-WDC_WD5000AAKS-00YGA0_WD-WCAS84837814-part2 /mnt/backup          ntfs-3g    users,gid=users,fmask=133,dmask=022,locale=en_US.UTF-8 0 0
/dev/disk/by-id/ata-WDC_WD5000AAKS-00YGA0_WD-WCAS84837814-part6 /mnt/ubuntu          ext4       acl              1 2
/dev/disk/by-id/ata-WDC_WD5000AAKS-00YGA0_WD-WCAS84837814-part7 /mnt/ubuntu/home     ext4       acl              1 2
/dev/disk/by-id/ata-WDC_WD5000AAKS-00YGA0_WD-WCAS84837814-part4 /mnt/windows7        ntfs-3g    users,gid=users,fmask=133,dmask=022,locale=en_US.UTF-8 0 0

I use emacs since at university is the only one installed on all machines and students can use it from home connecting via ssh.
All PCs in the labs have Debian and Windows XP in multiboot. The programming courses are all on Unix/Linux programming.
The course I’m following now is about C concurrent programming in Linux. We’re asked to write a “Car sharing” client/server software
there is a HUGE amount of stuff I have to learn: debugging tools ( valgrind, ddd, …), make files, simple bash scripts, system calls, pipes, signal, sockets. (so this is not going to be my last thread in the “Programming/Scripting” area of the forum :slight_smile: )
Unfortunately there are no courses on C++, just a little about Java.
Thanks for your hint, I 'd like to use a full IDE like eclipse but I have to learn emacs.

I study too computer science in university. What programs do you use for C and C++ developing?

Do you use VB for client server and then Java or with C++ http://linuxgazette.net/74/tougher.html

Emacs , make ,gcc to write/compile.
gdb, ddd, valgrind for debugging.

what about you?

Programming and developing with C++,QT- creator and Fortran. I have finished with programming languages and now I study in my university thelematic.

Lucky! I wish I had a course like that

I love C++ as my main programming language and even in university C++ and object oriented programming is useful for many students, because if you do not know object oriented programming, C and C++ you can not understand Java and thelematic programming.

We do it all in C, but no graphic user interface