Skip to main content

bash: ./a.out Permission denied

 bash: ./a.out Permission denied
 sh: ./a.out Permission denied  


Huh! Why the hell it is giving this error. It was working just fine previously.

Reason 1:
So, you may get this error sometime. I found this one when i tried to execute my executable file (a.out) on one of my friend's computer. When i checked it out thoroughly, I found out that normally in every executable file, there is a tab in properties of files. That tab is "Permissions". There is an option "Execute : Allow executing file as program". Just mark it true :-).
a.out -> Right Click -> Properties -> Permissions -> Allow executing file as program

Reason 2:
Try running the file as root. You may not have permission to run the file, using sudo might work or change the permissions by using chmod.

Note: This error might occur due to some other problems. I wrote this article in order to help those who have situations as described above. But please mention here if this kind of error is not going, I would test it.

Comments

Popular posts from this blog

error: invalid application of ‘sizeof’ to incomplete type ‘struct ’

list.c:47:39: error: invalid application of ‘sizeof’ to incomplete type ‘struct Litsnode’ So, I was trying to run a program based on linked list and this is what I got. This is a very silly problem. I am mentioning it here just to help those who got frustrated like me :-\ Let me show you the line where this error occurred : 46   struct Listnode * newnode; 47   newnode = (struct Listnode *) malloc(sizeof(struct Litsnode)); Now, View it properly. Check the name(spelling) of the structure mentioned to sizeof : " struct Li ts node ". Though the defined name of the structure was : " struct Listnode " That's it.  This happens all the time that we may type something wrong. The important thing is to identify it. :-) Feel free to give any suggestions :)

Expandable Arrays in C : behind the code

Arrays. They are beautiful. In C, we always try to work through restrictions arrays have i.e the size of the array must be statically defined. We always want a dynamic array whose size can be decided at run-time. There are ways which we use widely for e.g by using pointers and then dynamically allocating memory to it using malloc or calloc. But depending on the situation, we might require more efficient and organizable ways. I will explain the concept with a series of examples as in how simple arrays evolved to the tricky expandable ones. The classic way is to use pointers This snippet will allocate a memory block of size = array_size(integer array). Though this is not what I wanted to explain because this way is too clumsy. Imagine if you need 10 dynamic arrays in your program, you have to write these four lines each time and you have to keep track of all the 10 sizes. A better way is to use structures: We can simply create a structure containing two elements: array_size and...

The First C Program - Hello World! : Behind the code

This code will print Hello World! as output. #include <stdio.h> int main() { printf("Hello World!\n"); return 0; } To understand more, I would recommend to go through following: 1. Preprocessor macros # directive is for C preprocessor. #include simply looks for file stdio.h and includes the complete file in the current program. stdio.h is a header file which contains the declaration of variables, macros and functions of C standard library. 2. main() function This is the function which acts as starting point for C program. Its return type is int, which is followed as per ISO C89/99 standard. The system considers a program to have run successfully if at the end, it returns 0. So, in my opinion, this might have been the reason to choose int as the return type of main. 3. Logic Further, more functions and logic can be included inside main() to complete a desired task. In the above program, we are only printing one line and thats "Hello World!". 4...