1

I had a C program and made it executable on my 32 linux mint. For assignment purposes I had to test if it was working on university pool computers. I honestly don't know which linux distributions are installed there, just had two minutes didn't really take a look but I know that it's also 32 bit system.

So when I tried to run it in terminal (./program), I got bash permission denied error, which I know means that the file is not executable So I ran chmod u+x program command again to make it executable and then it worked, my program was working just fine as on my laptop.

Does anybody know what can be the reason for that? I mean, obviously, my file is executable, at least on my linux mint, what can be the reason that it is not on some other linux distribution?

Maybe I have to make it executable in another way? I only know the one mentioned earlier chmod u+x program.

UPDATE:

as mentioned in the comments the way I transfered my file to university computer was: download it from google drive. Now I tested on my laptop but to another system (UBUNTU), I tried again downloading from google drive the single file and the problem was same: not executable. Then I tar-ed the file (as Richard suggested) and after extracting it file was executable right away, so this leads me to conclusion that if I tar it, it should also be executable to any other system , in this case my university computer.

Leonardo
  • 123

1 Answers1

3

Because you had not done chmod u+x, non unix files systems will not store this data, it is outside of the file: the execute bit was not copied to google-drive. Therefore you had to run chmod again.

On the machine that you compiled it you did not have to run chmod, as the compiler does this for you.

As long as you keep it within the Unix eco-system, the x bit will remain. However google-drive is not Unix (though it runs on Unix). tar is a program that can wrap us a load of files/directories into a single file, along with all of there meta-data.

  • I am not sure I follow, you are saying that instead of chmod u+x, I have to do chmod +x and it will work? – Leonardo Jan 19 '17 at 18:29
  • no the u or lack of it is not relevant, I updated the answer, to avoid confusion. – ctrl-alt-delor Jan 19 '17 at 18:40
  • But, I did chmod u+x – Leonardo Jan 19 '17 at 18:43
  • Yes as you said in the question “so I ran chmod u+x program command again to make it executable and then it worked” (emphasis mine). – ctrl-alt-delor Jan 19 '17 at 18:44
  • aha, okay, so you mean that because I had not done it on university computer that's why it did not. Okay, now my question is, what should I do so that I will not have to run chmod u+x on university computer? where is the executable bit and how can I conclude it with my file? – Leonardo Jan 19 '17 at 18:48
  • If you tar a file or directory then all Unix meta data is stored. – ctrl-alt-delor Jan 19 '17 at 18:50
  • sorry if I ask too much but one more. suppose I have a file 'program.c' I made it executable with chmod u+x program.c. then I made tar of 'program' and sent it to university computer, when I extract it I will get 'program' again, this time execute bit will be included and I will not have to do chmod u+x anymore? – Leonardo Jan 19 '17 at 18:52
  • @Leonardo probably what your school is expecting you to do is copy your source code file(s) to the university computer, and compile your program there. Then you won't get any nasty run-time surprises. – steeldriver Jan 19 '17 at 19:15
  • You will get program.c with execute bit set, it will not compile it. Setting execute bit on a C source file is pointless. As it will not execute, probably some error about can not find command main or sum such error, as the shell will try to interpret it. – ctrl-alt-delor Jan 19 '17 at 19:18
  • @steeldriver well, the problem is that there are dozens of computers at university pool, they all run the same system but if I do chmod on computer x and they test it on computer y, I guess there is gonna be the same problem – Leonardo Jan 19 '17 at 19:44
  • from my answer — “As long as you keep it within the Unix eco-system, the x bit will remain.” – ctrl-alt-delor Jan 19 '17 at 21:09