LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Home Forums Tutorials Articles Register
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
  Search this Thread
Old 11-09-2011, 06:37 PM   #1
pottzie
Member
 
Registered: Aug 2009
Posts: 150

Rep: Reputation: 15
How does a program "find" another file or program when it calls one?


If the question doesn't tip you off as to how little I know, I don't know what will. Having said that, I'm trying to figure out how any program can call for a file, any file, when it runs. I know that my Linux system sometimes squawks when I enter something in bash without giving it a file path. And while I've gotten the examples that I've copied from Java tutorials to compile, when I read something saying that Java applets can be imported by a html script, the examples always leave out (or my mind can't grab) where and how the connection happens. I know this has got to sound strange to anyone with any kind of experience, but all I see is "There's this applet file, and it can work in a web page." I need some more info.
Is the applet, let's say I want to copy the Wkipedia example:http://en.wikipedia.org/wiki/Java_applet
and say I call the file something that the compiler can turn into something that runs. Then I guess I create a html page and somehow get the page to load or run in Firefox...I guess. Who knows? And does the applet come from anywhere on the web, or will it just work on my computer, and nowhere else?
And then there's the idea that almost every file I've installed has called on other files, especially libraries. When they install, I guess ./compile, make and make install commands make it so that I don't have to know how it works, but when you program, how does tab A find slot B when that's what's supposed to happen?
Sorry if this is dumb, I just haven't seen a good explanation of how all these files and programs connect.
 
Old 11-09-2011, 06:41 PM   #2
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 454Reputation: 454Reputation: 454Reputation: 454Reputation: 454
Quote:
Originally Posted by pottzie View Post
If the question doesn't tip you off as to how little I know, I don't know what will. Having said that, I'm trying to figure out how any program can call for a file, any file, when it runs. I know that my Linux system sometimes squawks when I enter something in bash without giving it a file path. And while I've gotten the examples that I've copied from Java tutorials to compile, when I read something saying that Java applets can be imported by a html script, the examples always leave out (or my mind can't grab) where and how the connection happens. I know this has got to sound strange to anyone with any kind of experience, but all I see is "There's this applet file, and it can work in a web page." I need some more info.
Is the applet, let's say I want to copy the Wkipedia example:http://en.wikipedia.org/wiki/Java_applet
and say I call the file something that the compiler can turn into something that runs. Then I guess I create a html page and somehow get the page to load or run in Firefox...I guess. Who knows? And does the applet come from anywhere on the web, or will it just work on my computer, and nowhere else?
And then there's the idea that almost every file I've installed has called on other files, especially libraries. When they install, I guess ./compile, make and make install commands make it so that I don't have to know how it works, but when you program, how does tab A find slot B when that's what's supposed to happen?
Sorry if this is dumb, I just haven't seen a good explanation of how all these files and programs connect.
Look up

PATH environment variable
LD_LIBRARY_PATH environment variable
.

Read

man 3 exec
man ld
man ld.so
.
 
Old 11-09-2011, 07:00 PM   #3
pottzie
Member
 
Registered: Aug 2009
Posts: 150

Original Poster
Rep: Reputation: 15
Thanks for the links, I just "skimmed" them but they look like they answer some of what I need.
I'm still stuck on the applets, or whatever, accessing via the web. The picture I have is that the html page can call "http.www.whatever" via <src>. But how or where is the applet? I use the img src a lot when I want to put something into a page, usually one where I just type into a form, as I've never created a web page. But I haven't made anything that generates a url to refer to, so I'm fuzzy about how a html page gets made.
 
Old 11-09-2011, 09:11 PM   #4
Juako
Member
 
Registered: Mar 2010
Posts: 202

Rep: Reputation: 84
Wait. You refer to three different things, that maybe remotely share a common aspect: "they hide some functionality" and thus some stuff seems transparent to you or to other things. Such aspect is embedded in everything, software or hardware and its called "abstraction".

Aside from that, the three things are unrelated:

The first one is how you type a command/program/script name in a command line and stuff gets executed. That has to do with the shell (the program that shows that command line and accepts your input) and a named value the shell pays attention to: its name is PATH and you refer to it as $PATH when you want to print it (type echo $PATH). The value is just a list of paths separated by colons. The shell looks for the program you want to run in these paths. Usually it will contain the common paths were programs are stored in Linux: /bin, /sbin, /usr/bin and /usr/sbin, but there are other locations too and you can add as you like more directories, and the executables (programs or scripts) stored there won't have to be invoked with a path. By the way, you can see where a program is located in your system with the command "which" (for example "which ls").

If you used the "echo $PATH" command before, the shell didn't even had to check $PATH to find the "echo" command. This is because "echo" is not a standalone program, stored in a file somewhere. It's an internal shell command, called a "builtin". You can see a list of builtins typing "help", and "help somebuiltin" will give you extra help on that builtin (I'm assuming you are using the the-facto shell in Linux: Bash).

So this is how the shell does its magic and runs something with you only typing a word. It ABSTRACTS you from knowing where a program is stored, and it abstracts you from the fact that some are binary programs, some are scripts, and some others are builtin commands (in fact it's a bit more complicated, this is just an overlook).

Second thing: Java
The support to embed Java (not Javascript, that is another lang) programs in HTML has to be provided by the browser, usually with the support of a browser plugin for Java, which implements the Java runtime and libraries. If you don't have this plugin your browser won't be able to do anything with a Java applet and you won't be able to use it.

How the hell is that you "embed Java in HTML" ?? Actually nothing is "embedded" in HTML as HTML is TEXT. BUT, in HTML you can "refer" to all kinds of objects. You can say "at this point render this image, look is a png and is at that computer, accesible by this protocol, and is located in this path at that computer" as your browser reads these references, it will connect again to where it's necessary and ask for stuff. Stuff is called "a resource".

The same way you refer to images, you refer to Java applets stored somewhere. The browser then gets the applet, and providing it has a Java plugin it hands over the applet to the plugin, and the plugin executes the applet.

Now, the plugin is a program running in your computer (which is running another program: the applet). The plugin has access to your *real environment* (operating system and libraries) as any other program, and it provides a *virtual environment* for the Java applet, which is *always the same*. This is how Java applets can run in many computers/operating systems: they don't operate with the real environment, as a normal program. They operate with the Java environment. Theres a level of indirection. There's a LEVEL OF ABSTRACTION, that allows Java applets to work everywhere a plugin for Java is able to function, hence they are subject to be transferred over networks between heterogeneous systems.

Note that the same accounts for flash programs, or Javascript programs, or any other "program content" to be distributed via web: as long as your browser has some component able to "interpret and run" the content, it can be delivered an will run in your system. The browser is then providing OS and hardware abstraction to these programs (at the cost of lots of CPU power sometimes...*cough*flash*cough*silverlight*cough*)

Third thing: system libraries and communication between programs
Well, these are two different things. And the way you put it you seem like saying "I want to know how programs interact with each other". The answer is: in a gazillion ways. So to end these neverending post I will refer only to system libraries, and in short tell you that you are on track when you guess that "./configure ; make" somehow links a program to the libraries it needs.

Abstraction again: those two commands do an awful lot of things, like checking you have the needed libraries and versions of them correctly installed in your system, configuring options and features for the program you are about to compile, compiling the program and LINKING it to the libraries it uses. Linking can be "static", when the functions that the program uses from the libraries are included into the program when its finished, or "dynamic" when only a REFERENCE to the function/library is stored in the program.

When the shell runs a binary program, it really asks the Linux Kernel to execute it, and the Linux kernel is who sets up the environment needed for the program to run, loads it into its own memory area, and transfers the control of the CPU to the first instruction of the program. But before doing so, it also runs a special code that it loads along with the program: this code in turn looks up what needed functions and libraries are used by the program, and loads them too, and after this the program is ready to run. Another way of using dynamic libraries is by a program explicitly asking for some function from some library.

Note that there is a tradeoff: with statically linked programs you get a fat executable with all the code in it. It doesn't depend on anything to load and run. Dynamically linked code instead is lightweight, but at the cost of being slightly slower during run time because of the time and cpu used to look up what's needed, find it, load it and arrange the references so the program is able to finally use the god damn functions. There are techniques to mitigate this penalties too (I won't describe them though).

So again, these are abstractions so a program can more or less say "I need X function" and the kernel can say "allright lemme get it for ya".

These are awfully gross simplifications of very big/complex subjects so you can aprehend more or less what they are about, of course. But, it's something.

Dinner calls. It's my price for having written such a gigantic post. I promess I'll never do this again in my life.

Hope this doesn't add up more confusion! Cheers!

Last edited by Juako; 11-10-2011 at 01:15 PM.
 
1 members found this post helpful.
Old 11-10-2011, 12:35 PM   #5
pottzie
Member
 
Registered: Aug 2009
Posts: 150

Original Poster
Rep: Reputation: 15
Wow! Not only is this one of the best answers I've ever recieved to a qusetion, it's like a wonderland of answers. Thanks isn't a big enough word in this case!

I asked myself a few questions after posting this, and somehow stumbled onto a good online source of info:
http://en.wikiversity.org/wiki/Intro...ization_part_1

It seems to have a lot of what I haven't learned yet, and I'll be going through it for a while, I'm sure. But you gave me a ton of new "scope" that I hadn't digested yet, and I'm sure I'll have more to ask at some point.

Still foggy on how to make a simple applet (on my computer) and display it on a HTML file, again on my computer. I use nano to write the .java file, and everything I've read seems to indicate that I can use nano to make the HTML page too, but how would I load that HTML file to, say, Firefox?
 
Old 11-10-2011, 01:26 PM   #6
Juako
Member
 
Registered: Mar 2010
Posts: 202

Rep: Reputation: 84
Hey, glad I've managed to help you get on track! It was that or confusing you even more, so I'm just happy it turned out right.

Here's an article on embedding Java applets, I don't use Java so I can't help you more with that. But typing Java in a text editor won't get you the applet, you should compile it.

Here's another page on Java in Linux, and make sure you read the Wikipedia entry on java applets in its entirety.

That said, I personally can't recommend that you start learning Java these days. It's far more useful (and less booooooooooooooooriiiiiiiiiiiiiing) to learn HTML5/CSS3/Javascript to develop for browsers, and Apache+PHP/Python/Ruby/WhateverLanguage and some database for server side web development. IMHO, Java is more or less going the way of the dodo, or at least being more and more relegated to ultra enterprise niches, where (I hope) eventually will be overthrown too.
 
Old 11-10-2011, 02:01 PM   #7
ntubski
Senior Member
 
Registered: Nov 2005
Distribution: Debian, Arch
Posts: 3,782

Rep: Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083Reputation: 2083
Quote:
Originally Posted by pottzie View Post
I use nano to write the .java file, and everything I've read seems to indicate that I can use nano to make the HTML page too, but how would I load that HTML file to, say, Firefox?
Just run
Code:
firefox your-page.html
from the command line.
 
1 members found this post helpful.
Old 11-10-2011, 02:10 PM   #8
SigTerm
Member
 
Registered: Dec 2009
Distribution: Slackware 12.2
Posts: 379

Rep: Reputation: 234Reputation: 234Reputation: 234
Thumbs down

Quote:
Originally Posted by ntubski View Post
Just run
Code:
firefox your-page.html
"File->Open" menu or "Ctrl+O" in any browser. Keep things simple.
 
Old 11-10-2011, 10:07 PM   #9
pottzie
Member
 
Registered: Aug 2009
Posts: 150

Original Poster
Rep: Reputation: 15
Thanks again. I've never seen that in any tuttorial...probably because it's something everyone knows.
Now I do too. Again, thanks.

Edit: Just got the applets to run. This looks like it's going to be fun!

Last edited by pottzie; 11-11-2011 at 12:08 AM.
 
  


Reply



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



Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Finding out which process calls a program/script ("/sbin/usbmod") JZL240I-U Linux - Software 4 06-01-2010 06:42 AM
Can't change wallpaper, I keep getting the message- could not find the program "set" andyairlie Linux - Newbie 1 12-26-2008 06:00 PM
New Newbie looking to create or find Linux based "Ghosting" program sbhoffmaster Linux - Software 5 06-29-2007 05:04 PM
Stock market "find the best price model" program cigarstub Programming 1 01-07-2007 08:24 AM
Just finished compiling Wine, getting "couldn't find program" error Maronflower Linux - Software 1 11-10-2003 06:50 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:15 PM.

Main Menu
Advertisement
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
Open Source Consulting | Domain Registration