8

I'm fairly new at this stuff, but essentially: there are programs and there are processes. A program is a file that spawns a process, when executed.

You can't delete a program if there is a process still associated to it. The process needs to be killed first.

This seems to be the case for Java programs too. However I'm curious as to why - isn't the entire thing loaded into the JVM anyway?

Saturn
  • 17,888
  • 49
  • 145
  • 271
  • 1
    The JVM don't load every thing in the same moment, it will load the classes when needed. – Marco Acierno Jun 09 '14 at 22:55
  • Could you link to the place you saw "program" defined? In *nix, the kernel spawns processes, then processes spawn processes (and threads). – David Ehrmann Jun 09 '14 at 22:56
  • 1
    This is going to be OS and JVM specific. – Samuel Edwin Ward Jun 10 '14 at 00:12
  • I'm not sure that there's any mechanism to prevent a .class file from being deleted while the class is running in a JVM. Generally speaking (there may be odd exceptions), the JVM will load everything it needs from the .class when it's "loaded" by the class loader, so the .class file itself is not needed after that. – Hot Licks Jun 10 '14 at 01:22

2 Answers2

4

"Deleted file" involves som OS-semantics. Under Unix/Linux a file may be deleted and all open file handles stay valid. When the last open file handle vanishes, the space occupied by the deleted file is returned to the pool of free space.

Under Windows there may be other mechanisms.

blafasel
  • 1,091
  • 14
  • 25
2

The JVM works as a Just-In-Time (JIT) compiler. There are many sources of information on JIT compilation, but basically as a java program is running it will encounter parts of the program that are needed, these pieces of the program are in .class files. These .class files is just an intermediate form of Java code (it's not quite Java code, but not quite machine code, yet). Obviously, compiling at runtime (JIT) takes resources (CPU cycles) and, thus, time. So, the JVM only loads pieces of the program that it needs to minimize wasted CPU cycles.

But yes, your understanding of process/programs is correct. To sum up: A process is a running instance of a program. This running program, then can spawn even more processes or threads to perform work.

Rich E
  • 233
  • 2
  • 10