LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 01-11-2006, 12:41 AM   #1
GEJOE DANIEL
Member
 
Registered: Aug 2005
Posts: 81

Rep: Reputation: 15
executable files in linux and windows...


I know that a system with windows (without strong anti-virus) would be easily pulled down by the viruses in the LAN whereas in linux it's no so..
I heard that in Windows the files are identified by their file extension like .exe,.com,etc(andhence the viruses with .exe extensions run easily on windows system).. whereas in Linux it is by the file type and hence .exe or whatever executable file is their it won't run without the permission of the superuser.Please explain.....
 
Old 01-11-2006, 12:50 PM   #2
iainr
Member
 
Registered: Nov 2002
Location: England
Distribution: Ubuntu 9.04
Posts: 631

Rep: Reputation: 30
Sort of...

It comes down to giving different users the ability to do different things. Unix/Linux is a multi-user system so the assumption is you have one user (root) who can do anything and others who can do less.

Windows was a single user system where anyone using it had superuser powers. Newer versions of Windows (NT, 2000, XP) are multi-user, but by default for home users they are superuser so it doesn't make much difference.

Most of the ways to break systems (or break into them) require superuser access. In Windows, the account you use to browse the internet probably has that access. In Linux it probably doesn't : you use a normal user account and only access root when you need to.
 
Old 01-12-2006, 11:13 AM   #3
GEJOE DANIEL
Member
 
Registered: Aug 2005
Posts: 81

Original Poster
Rep: Reputation: 15
executable files...

what about the executable files in windows and in linux??
In windows any file with .exe extension is an executable file..
but in Linux the extension doesn't matters...then how is the executable file known/identified???
 
Old 01-12-2006, 11:37 AM   #4
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: ubuntu
Posts: 2,524

Rep: Reputation: 93
Quote:
Originally Posted by GEJOE DANIEL
what about the executable files in windows and in linux??
In windows any file with .exe extension is an executable file..
but in Linux the extension doesn't matters...then how is the executable file known/identified???
As a permission to execute the file. Just like read and/or right permissions.
 
Old 01-12-2006, 11:45 AM   #5
GEJOE DANIEL
Member
 
Registered: Aug 2005
Posts: 81

Original Poster
Rep: Reputation: 15
for giving read/write/execute permission it should be an
executable file.So my question is how do we/linux knows that
the file is executable.Once only if it's executable then the permission ,matters???
isn't it??
please correct me if i'am wrong...
 
Old 01-12-2006, 12:13 PM   #6
zoroaster
LQ Newbie
 
Registered: Mar 2003
Location: Owen Sound, Canada
Distribution: debian
Posts: 9

Rep: Reputation: 0
Suppose it depends what you mean by "executable file". In Windows you can name an arbitrary file with the .exe extension. That doesn't make it an executable file. Try it and find out. Try renaming an html file with a exe extension. Windows shell will pass the operation to the kernel, but you will get an error.

Similarly you can set the execute permission for an html file on a linux machine. The shell might try to execute the file, but it won't do much. On the other hand, I could compile a program and execute it even if the execute permission is not set using the exec command. The execute permission is a convenient organizer, but it doesn't really define an executable file. And it doesn't make the system any more secure.

What really makes a file executable? I would say that if the operating system, including any running process (such as bash) recognizes the code as valid instructions, then the code is executable. For instance, you can create a bash script and exec it without setting the execute permission - that's valid. You can create a python script, same thing. Usually the type of script is defined in the first line with #!/bin/bash or #!/bin/python identifier. That's how bash recognizes an executable file. On the other hand, binary files are defined when they are linked - the definition lies in the executable file's header, depending on what executable file formats the OS recognizes. For instance, the gcc linker can create ELF or a.out binaries. Most linux kernels handle both ELF and a.out.

hope this helps.
 
Old 01-12-2006, 01:39 PM   #7
schneidz
Senior Member
 
Registered: May 2005
Location: boston, usa
Distribution: fc-12/ fc-11-live-usb/ aix
Posts: 1,951

Rep: Reputation: 158Reputation: 158
in m$ windoze the file is associated by the extension.

in *nix the four cc code (first 4 bytes of a file) is used to identify the type of file.

the file command can be used to see the type of file.

relative thread:
http://www.linuxquestions.org/questi...d.php?t=383956

Last edited by schneidz; 01-12-2006 at 01:45 PM.
 
Old 01-12-2006, 01:59 PM   #8
jtshaw
Moderator
 
Registered: Nov 2000
Location: Seattle, WA USA
Distribution: Ubuntu @ Home, RHEL @ Work
Posts: 3,892
Blog Entries: 1

Rep: Reputation: 63
I'll you give a for instance with linux.

Say I have two files:

file1.php:
Code:
<?
phpinfo();
?>
and

file2.php:
Code:
#!/usr/bin/php
<?
phpinfo();
?>
Both files are marked executable by my user.
You execute file1.php and it'll give you an output like this:

Code:
j_shaw@lois /opt/j_shaw $ ./file1.php
./file1.php: line 1: ?: No such file or directory
./file1.php: line 2: syntax error near unexpected token `;'
./file1.php: line 2: `phpinfo();'
The second one gives you an output like this:
Code:
j_shaw@lois /opt/j_shaw $ ./file2.php
phpinfo()
PHP Version => 4.4.0-pl1-gentoo

System => Linux lois 2.6.14-hardened-r3 #1 PREEMPT Thu Jan 5 09:20:52 EST 2006 i686
Build Date => Dec  1 2005 15:43:04
...
So what basically happens when you try and execute something is the system first tries to find out what it is. If it is a binary type file it'll try and find the _start symbol (aka int main(...) in a C program) and go from there.

If it is an ascii file it first sees if an interpreter is specified (in the case of File1 there is not, in the case of File2 the #!/usr/bin/php specifies to use the /usr/bin/php program to interpret the file. If there isn't then it uses the default shell to attempt to execute it. This explains the above results because bash, my default shell, can't understand the php code.

You'll notice that the extension (.php) on my above files does not tell the system anything, as it does not interpret file1.php with php just because it has a php executable.

Last edited by jtshaw; 01-12-2006 at 02:05 PM.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Difficulty downloading executable Macintosh files in Linux Tired8281 Linux - Newbie 1 05-08-2004 06:23 PM
What is the extention of Linux executable files. AskMe Linux - Newbie 4 10-22-2003 01:55 PM
all files in mounted windows partition are executable zovres Linux - Newbie 4 07-17-2003 06:44 PM
running windows executable in linux anamika123 Linux - Software 8 06-05-2003 12:31 PM
Converting perl files to executable mac files mrozkan Programming 0 04-16-2002 09:56 AM


All times are GMT -5. The time now is 04:50 AM.

Main Menu
 
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration