Sudden loss of permissions

This is a discussion on Sudden loss of permissions within the Tech Board forums, part of the Community Boards category; Hi, I'm new to Linux, C programming and this forum, so I apologize if my question is out of place ...

  1. #1
    Registered User
    Join Date
    Dec 2010
    Posts
    4

    Sudden loss of permissions [solved]

    Hi,

    I'm new to Linux, C programming and this forum, so I apologize if my question is out of place here but I'm hoping some of you could help me out.

    I've been writing some simple C programs under Linux for a class I'm taking. Since I'm not a Linux user, I've been running Ubuntu in a virtual machine (VMare in case that's somehow relevant). Everything has been working fine until today I start up the VM and try to execute one of my programs ("mydiff" - one of the assignments for my course), only to get the following:

    bash: ./mydiff: Permission denied

    The first thing I tried was changing the file permissions, though I have no idea why they would have changed themselves, but I still have read and write permissions on the file. I noticed there was a checkbox for "allow executing file as program," which I enabled. Upon doing so I now receive this:

    bash: ./mydiff: cannot execute binary file

    So at this point I was pretty confused and since I only run the virtual machine for the purpose of C programming and don't have anything else on it, I decided to just copy my C programs over to Windows, delete the entire virtual machine and create a new one. I did that, copied the C files over again and am still getting the same error!

    Note: this is NOT just happening with that one mydiff program but with ALL of my C programs. When I delete the binaries and compile new ones using the makefiles, I still get the same error.

    Does anyone have an idea what is the cause of this?

    Taylor
    Last edited by ExAmerican; 12-12-2010 at 10:30 PM.

  2. #2
    Registered User
    Join Date
    May 2010
    Location
    Naypyidaw
    Posts
    1,314
    Is your executable compiled on linux with gcc?
    What's the output of ls -l myprogram ? # myprogram is your executable

  3. #3
    Registered User
    Join Date
    Dec 2010
    Posts
    4
    Thanks for the quick response!

    Quote Originally Posted by Bayint Naung View Post
    Is your executable compiled on linux with gcc?
    What's the output of ls -l myprogram ? # myprogram is your executable
    The program is compiled with gcc. We have very strict coding guidelines in this course so actually we have to compile with: -ansi -pedantic -Wall -c -g -D_XOPEN_SOURCE=500 (not sure if that may be relevant or not).

    ls -l mydiff gives me:
    -rwxr-xr-x 1 taylor taylor 5920 2010-12-12 17:58 mydiff

  4. #4
    Registered User
    Join Date
    May 2010
    Location
    Naypyidaw
    Posts
    1,314
    It seems you've execute permission.
    If your code is compiled with gcc(on your vm), ./mydiff should work...

  5. #5
    Registered User
    Join Date
    Dec 2010
    Posts
    4
    Hah yes I also agree that it SHOULD work but for some reason it doesn't!

    Yes the code is compiled on my vm. Like I said, I have also tried rebuilding it by deleting the binaries and recompiling the source but I always have the same problem.

    taylor@ubuntu:~/SysProg/1A$ ls -l mydiff
    -rw-rw-rw- 1 taylor taylor 5920 2010-12-12 21:13 mydiff
    taylor@ubuntu:~/SysProg/1A$ ./mydiff
    bash: ./mydiff: Permission denied

    taylor@ubuntu:~/SysProg/1A$ ls -l mydiff
    -rwxrwxrwx 1 taylor taylor 5920 2010-12-12 21:13 mydiff
    taylor@ubuntu:~/SysProg/1A$ ./mydiff
    bash: ./mydiff: cannot execute binary file
    Last edited by ExAmerican; 12-12-2010 at 10:16 PM.

  6. #6
    Registered User whiteflags's Avatar
    Join Date
    Apr 2006
    Location
    United States
    Posts
    7,638
    Just to verify, the current working directory is also the directory where mydiff is located, correct? You need to cd to the place where mydiff is before ./mydiff works.

  7. #7
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,452
    You've got -c in the command line.

    linux - gcc compiled binaries give "cannot execute binary file" - Stack Overflow

    Example
    Code:
    $ gcc foo.c -lm
    $ ls -l a.out 
    -rwxr-xr-x 1 sc sc 7221 2010-12-13 05:18 a.out
    $ file a.out 
    a.out: ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.15, not stripped
    $ gcc -c foo.c
    $ ls -l foo.o
    -rw-r--r-- 1 sc sc 1520 2010-12-13 05:18 foo.o
    $ file foo.o
    foo.o: ELF 32-bit LSB relocatable, Intel 80386, version 1 (SYSV), not stripped
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  8. #8
    Registered User
    Join Date
    May 2010
    Location
    Naypyidaw
    Posts
    1,314
    Maybe can you create simple C file.
    say hello.c
    and type

    Code:
    #include <stdio.h>
    
    int main(void)
    {
      printf("Hello World!\n");
      return 0;
    }
    and compile with
    > gcc hello.c
    > ./a.out

  9. #9
    Registered User
    Join Date
    Dec 2010
    Posts
    4
    @ Salem - yes you are correct, I just came to the same conclusion myself.

    Compiling with just "-ansi -pedantic -Wall -g -D_XOPEN_SOURCE=500" creates a working binary that runs without problems.

    Thanks to everyone for your input!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. displaying file permissions
    By bobthebullet990 in forum C Programming
    Replies: 5
    Last Post: 11-26-2005, 06:04 AM
  2. Networking (queuing delay, avg packet loss)
    By spoon_ in forum A Brief History of Cprogramming.com
    Replies: 0
    Last Post: 09-05-2005, 11:23 AM
  3. Guaranteed weight loss
    By Glirk Dient in forum A Brief History of Cprogramming.com
    Replies: 8
    Last Post: 05-12-2004, 06:11 AM
  4. C File permissions
    By vipers in forum C Programming
    Replies: 1
    Last Post: 04-24-2004, 12:00 PM
  5. Configurations give different results
    By Hubas in forum Windows Programming
    Replies: 2
    Last Post: 04-11-2003, 11:43 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21