Program vs Process (low level concepts)

NeetCodeIO
14 Sept 202418:48

Summary

TLDRThe video script from 'Program is not a Process by Core Dumped' explores the nuances between a program and a process in computing. It explains that a program is a passive sequence of instructions stored on disk, while a process is an active, temporary instance of a program running in memory. The script delves into early computing history, the evolution of batch systems to time-sharing operating systems, and the concept of concurrency. It also discusses the memory layout of processes, including text, data, stack, and heap sections, and touches on the differences in how compiled and interpreted languages like C, Java, and Python are executed.

Takeaways

  • 🖥️ Programs vs Processes: A program is a sequence of instructions stored on disk, while a process is an instance of a program running in memory, with its own allocated resources.
  • 🧠 A process is active: Programs are passive entities stored on disk, but when they are executed, they become active entities known as processes.
  • 💾 Memory allocation: Processes have distinct memory regions for instructions (text section), global variables (data section), and temporary data (stack and heap).
  • 🔀 Single core concurrency: Early home computers popularized concurrency, where a single-core CPU switches between multiple processes to simulate multitasking.
  • 📝 Compilation in C: In compiled languages like C, the program is converted into CPU instructions and saved to an executable file with data and instructions stored separately.
  • 🐍 Interpreted languages: In Python and JavaScript, there is no compilation into machine code; instead, the interpreter executes the code at runtime, making them distinct from compiled languages like C.
  • 📚 Interpreter process: In Python, when the interpreter runs, it loads the Python code into memory as data, while the interpreter itself becomes the active program (process).
  • 📝 Text vs Data regions: The text section in memory remains constant for the duration of the process, while the data section may change based on runtime actions.
  • 🔁 Recursive functions and memory: Stack memory, often limited, is used for function calls, and recursive functions can lead to stack overflows if too many layers are created.
  • ⚙️ Separate processes, shared programs: The same program can run as multiple processes simultaneously, each having its own memory space but the same set of instructions (text section).

Q & A

  • What is the main difference between a program and a process?

    -A program is a passive entity, typically an executable file stored on disk, while a process is an active entity that is created when the program is loaded into memory and executed. A process has its own memory space, including text, data, stack, and heap sections.

  • How does the memory layout of a process differ from that of a program?

    -The memory layout of a process includes the text section (which holds executable code), the data section (holding global variables and constants), the stack (for function calls and local variables), and the heap (for dynamic memory allocation). A program is simply a file, while a process is a live execution with allocated memory.

  • What is the significance of the text section in a process?

    -The text section contains the executable code of the program. It is a part of the process’s memory that remains constant in size and content throughout the execution of the process.

  • Why is recursion sometimes discouraged in programming, according to the transcript?

    -Recursion can be discouraged because recursive functions use the stack for each function call, which can lead to stack overflow if the recursion depth is too high. Stack memory is limited, and exceeding it can crash the program.

  • What is the role of the heap in a process's memory layout?

    -The heap is used for dynamic memory allocation during a process’s runtime. Memory from the heap is allocated and freed as needed, and the size of the heap can grow and shrink during the execution of the program.

  • How do interpreted languages like Python handle the difference between a program and a process?

    -In interpreted languages like Python, the source code is not directly executed by the CPU. Instead, the Python interpreter (itself a program) is executed, and the source code is loaded into one of the interpreter’s memory sections (typically the heap) as data to be interpreted.

  • Why is it important to distinguish between a program and a process in computing?

    -Distinguishing between a program and a process is important because a program is simply a file that can be executed, while a process is the running instance of the program with its own memory and resources. Multiple processes can run from the same program, but they operate independently.

  • How does Python handle global variables and string literals after compilation?

    -After compilation in Python, global variables and string literals are stored in the data region of the process. They are separated from the CPU instructions and can be accessed during runtime without being part of the executable code itself.

  • What is concurrency, and how does it relate to early computer systems?

    -Concurrency refers to the ability of a system to execute multiple processes or tasks at the same time, allowing for time-sharing. In early computer systems, this concept was introduced to allow multiple users or tasks to share the CPU's resources. Concurrency became popular with home computers, allowing single users to run multiple programs at once, even on single-core CPUs.

  • What happens when a Java program runs, according to the script?

    -When a Java program runs, it is executed within the Java Virtual Machine (JVM). Java code is compiled into bytecode, which is then interpreted or just-in-time compiled by the JVM. Each Java process typically runs with its own instance of the JVM.

Outlines

00:00

🖥️ Introduction to Programs and Processes

The narrator expresses their interest in a YouTube channel that delves into technical computer science concepts. The discussion opens with a question about the difference between a program and a process. The narrator offers an initial explanation, stating that a program is stored on disk and is static, while a process is in memory and more temporary. Early computer systems ran jobs in batch mode, but with the rise of time-sharing, user programs were executed concurrently, allowing multiple processes to run simultaneously. This leads to a deeper examination of the distinction between programs and processes.

05:01

💡 Concurrency and Memory Allocation

The video explores how early home computers popularized concurrency, even with single-core CPUs. The narrator speculates that concurrency refers to multiple processes running at the same time with the CPU context-switching between them. They dive into the difference between programs and processes, pointing out that a program is a set of instructions, while a process is an active instance of those instructions. The narrator begins contemplating how the memory sections of programs, such as global variables and stack memory, function once a program is compiled into executable code.

10:01

📂 Memory Layout and Processes

The narrator dives deeper into how programs interact with memory when they become processes. They explain that when a program is loaded into memory, it is divided into sections like the 'text section' for code and 'data section' for variables. While the text section remains unchanged, the data section can vary based on the program’s runtime behavior. The concept of memory allocation is discussed in terms of recursive functions and variable memory needs, explaining how a process uses memory differently than a static program.

15:02

🔍 Understanding Processes with Examples

The video provides a practical example of processes using a text editor. Opening two files in separate windows results in two different processes, even though the program is the same. The narrator highlights that each process has its own memory space, though the code (text section) is the same. They further explain that processes are an operating system-level concept, each with its own ID and memory management. While the video doesn’t go too deep into technical details, it emphasizes that a process is more than just an active program—it’s a complex entity managed by the OS.

💾 Interpreted Languages and Processes

The narrator discusses how interpreted languages like Python and JavaScript differ from compiled languages like C. Unlike compiled languages, which turn source code into executable files, interpreted languages run through an interpreter. Each time a Python program runs, a process is created, and the interpreter reads the source code. The narrator brings up an interesting point about how even though Python has a compilation step to bytecode, it's often overlooked due to its runtime nature. The interpreter manages both the text and data sections for these interpreted programs.

Mindmap

Keywords

💡Program

A program is defined as a passive entity, a set of instructions stored on a disk waiting to be executed. In the video, the speaker differentiates a program from a process, stating that a program resides in storage and needs to be loaded into memory to run. For example, the text editor application is referred to as a program before it's executed.

💡Process

A process is an active entity, which is a program in execution. The video explains that a process has its own memory layout and resources when running. For example, when two files are opened using the same text editor, each file runs as a separate process even though the program is the same.

💡Memory layout

Memory layout refers to how the memory is structured when a process runs, with different sections like the text, data, stack, and heap. The text section contains the executable code, and the data section contains variables and constants. The video discusses how memory is allocated for processes and varies in size based on what the program is doing.

💡Text section

The text section is the part of a process’s memory layout that holds the executable code. In the video, it is mentioned that this section never changes during execution, unlike other sections like the stack or heap. This is a core part of the process and differentiates the code from data and runtime memory.

💡Data section

The data section stores global variables and constant values used by a process. In the video, the speaker points out that this section can change in content, depending on what the program is doing, but not in size. It holds important information, like global variables in compiled C programs, as part of a process's memory.

💡Heap

The heap is a section of memory allocated for dynamic memory use during program execution. The video emphasizes that the heap grows and shrinks as needed, and it stores large or dynamically created data. The heap is used by the process to manage memory for things like variables created at runtime, such as a text file in a text editor.

💡Stack

The stack is another memory section used by a process, mainly for managing function calls and local variables. In the video, the stack is described as limited in size and used to store temporary data like local variables or manage function calls, including recursive functions. It grows and shrinks as functions are called and completed.

💡Concurrency

Concurrency refers to the ability to run multiple processes or threads simultaneously, or seemingly so by time-sharing CPU resources. The video touches on the history of concurrency, explaining how early computers and time-sharing systems introduced this concept to allow multiple programs to run at once. This is distinct from modern multi-core processors.

💡Interpreter

An interpreter is a program that directly executes instructions written in a high-level programming language. The video uses Python as an example of an interpreted language, where the Python interpreter runs the code. Unlike compiled languages, where the entire program is converted into machine code, an interpreter executes code line-by-line.

💡Compilation

Compilation is the process of converting source code written in a high-level language into machine code that can be executed by the CPU. The video contrasts compiled languages like C, where a separate compilation step creates an executable file, with interpreted languages like Python, which are executed directly by an interpreter after being converted to byte code.

Highlights

The distinction between a program and a process: a program is a passive entity stored on disk, while a process is an active entity in memory.

Concurrency in early computers allowed a single user to run multiple programs simultaneously, even with a single-core CPU, using context switching.

In computer science, programs are referred to as processes when executed, not programs.

The text section of memory stores executable code, while global variables and constant values are stored in the data section.

Heap and stack memory regions complement the data section for runtime memory allocation, such as user inputs and temporary variables.

The stack is used for local variables and function calls, while the heap is for dynamically allocated memory.

The stack has limited memory, which is why stack overflows can occur, especially in recursive functions.

The text section of a process's memory never changes in size or content during execution, but the data section's contents may vary.

In interpreted languages like Python, the interpreter itself is a process, while the Python source code is treated as data for the interpreter.

Global variables and string literals in a compiled C program are saved in the data region, while local variables go to the stack.

The difference between compiled and interpreted languages: in Python, source code is not executable by itself but is processed by the interpreter.

Processes associated with the same program, such as opening two text files in the same editor, operate in separate memory spaces.

Java programs are run by the Java Virtual Machine (JVM), which operates as a separate process to execute Java bytecode.

Even though Python source files are text, they are compiled to bytecode before execution by the interpreter for performance optimization.

Recursion, while theoretically valid, is discouraged because of memory limitations in the stack, which can lead to stack overflow.

Transcripts

play00:00

program is not a process by core dumped

play00:03

probably my new favorite YouTube channel

play00:05

because it takes me back to the days

play00:07

when I was just getting a computer

play00:08

science degree and I was actually

play00:10

learning about things that were

play00:11

interesting most people learn to code so

play00:13

they can actually build things that are

play00:15

genuinely useful not me I just like

play00:17

understanding how things work and this

play00:19

channel is going to let us do that a

play00:21

question that arises in computer science

play00:23

is what to call all the activities

play00:25

performed by the CPU I hate to pause it

play00:27

right now but I think so just based on

play00:29

the title The first thing that I think

play00:30

of is that a program versus a process

play00:32

what's the difference um I guess a

play00:35

process is just an instance of a program

play00:37

for example like for one program you can

play00:38

have multiple processes and a program I

play00:40

believe is just going to be stored on

play00:42

your dis so it's like persisted there

play00:44

versus a process is going to be stored

play00:46

in memory and it's going to be

play00:47

shortlived or temporary at the very

play00:54

least early computers were batch systems

play00:56

that executed work units called jobs

play01:00

as I discussed in my video about

play01:01

concurrency when time sharing operating

play01:03

systems emerged they were designed to

play01:05

share the CPU among multiple users so it

play01:08

was said that those systems ran user

play01:10

programs interesting I actually don't

play01:12

know very much at all about very early

play01:14

computers eventually the home computer

play01:16

Market popularized the use of

play01:17

concurrency to allow a single user to

play01:19

run multiple programs at once that's

play01:22

very interesting actually let me replay

play01:24

that did he say concurrency eventually

play01:26

the home computer Market popularized the

play01:28

use of concurrency the use of concurr

play01:29

currency what he means by that I think

play01:32

is not like this is like the invention

play01:34

of a multi-threaded or like multi-core

play01:36

CPU it's more that just you have

play01:38

multiple processes running at the same

play01:40

time and then the CPU is going to

play01:41

contact switch between them uh that's

play01:43

very interesting so that was probably

play01:45

even with a single core CPU to allow a

play01:47

single user to run multiple programs at

play01:49

once but in computer science we don't

play01:51

refer to these entities as programs but

play01:54

rather as

play01:55

processes so today we are going to learn

play01:57

the difference that's very interesting

play01:59

to this shows me how much I actually

play02:01

don't know because I thought Linux is

play02:03

just I I believe from its birth was

play02:05

using like processes so that's

play02:07

interesting it's kind of hard to believe

play02:09

that there was a point you literally

play02:11

couldn't run multiple processes at the

play02:12

same time just imagine living like that

play02:15

today I don't even think it's possible

play02:18

Concepts hi friends my name is George

play02:21

and this is core dumped for the vast

play02:24

majority the answer to this question

play02:25

seems obvious programs after all that's

play02:29

what CPU does right it runs programs but

play02:33

as I mentioned before in computer

play02:35

science the correct term is process

play02:37

that's technically correct I wonder how

play02:39

mad people would get though if you just

play02:41

said program kind of reminds me of the

play02:43

other day how I said pointer in

play02:45

technically the wrong context informally

play02:48

a process is usually defined as a

play02:49

program in execution even though this

play02:52

definition is technically correct what I

play02:54

find frustrating is that it is not

play02:56

enough to help a casual reader

play02:57

understand what a process is

play03:00

so let's start by establishing what a

play03:02

process is not think about this

play03:05

interesting I think he's right CU like

play03:08

the devil is in the detail to say that a

play03:10

process is an instance of a program

play03:12

isn't really getting into the hardware

play03:13

and like like I said kind of at the

play03:14

beginning the hardware matters like the

play03:16

dis versus like the memory where each is

play03:18

stored and how it's run and all that

play03:20

different programs are obviously

play03:21

intended for different purposes but in

play03:23

many respects they are similar when

play03:25

executing as they all reduce to the

play03:27

fundamental actions performed by the CPU

play03:31

and here's where we can start making

play03:32

distinctions a program is a sequence of

play03:34

instructions and the data that the CPU

play03:36

needs to accomplish a specific

play03:39

task now if you carefully Analyze This

play03:41

description you'll notice that it can

play03:43

also describe an executable file and

play03:46

that's because that's pretty much what a

play03:47

program is let's say like you have a c

play03:49

program you compile it it turns into

play03:51

like CPU instructions that the CPU is

play03:54

going to load into memory and execute

play03:56

that makes sense so what is this data at

play03:58

the top of my head I actually don't know

play04:00

cuz the executable file it has data

play04:02

itself what does that mean cuz I know

play04:04

when a process is running it's going to

play04:06

have some memory allocated like the

play04:08

stack space Etc but the executable file

play04:11

itself has data I'm curious about that

play04:15

so I wanted to at least have like a

play04:16

little bit of understanding of what that

play04:17

meant so I just went to chat gbt and

play04:19

asked it so can you give me a simple

play04:21

example of a c program after compilation

play04:23

what parts of it would be the CPU

play04:25

instructions and which parts of it would

play04:26

be the data I think that the CPU

play04:28

instructions are like Rel relatively

play04:30

straightforward in terms of like if you

play04:32

had conditional statements loops and

play04:34

things like that like the control flow

play04:36

that makes sense that those would turn

play04:38

into CPU instructions but I was

play04:40

surprised to see that so if you have

play04:41

like Global variables and for example

play04:43

string literals those are actually saved

play04:46

in the data region after the program is

play04:49

compiled and so local variables like

play04:53

this are going to be as we would kind of

play04:55

expect pushed onto like the stack space

play04:57

and I would assume like the same thing

play04:59

with recursive calls of course but it's

play05:00

interesting to me that a string literal

play05:02

like this would be saved not as like a

play05:05

CPU instruction but rather in the data

play05:08

region so what does that mean like if I

play05:10

had multiple print statements would that

play05:12

same string be copied multiple times I'm

play05:14

assuming not CU that sort of

play05:16

optimization could be made but actually

play05:18

now that I think of it on second thought

play05:20

if there are distinct strings and you

play05:22

want to update one of the strings you

play05:24

don't necessarily want both strings to

play05:25

be updated I think if we were to dig

play05:27

deeper into this we would probably be

play05:29

getting really into the realm of like

play05:30

operating system so I guess I won't do

play05:32

that right now but it does make sense

play05:34

that a lot of variables and just large

play05:36

amounts of data are going to be stored

play05:38

in the data region of an executable file

play05:40

separate from the code instructions and

play05:43

so all of that is going to be loaded

play05:45

into memory when it's actually run but

play05:47

there's going to be separate memory

play05:48

regions like the stack and probably the

play05:50

Heap that can complement the data

play05:54

section a program is that passive entity

play05:56

that resides in your storage waiting for

play05:58

you to click on it to tell the the

play05:59

computer to start running

play06:02

it as I've mentioned many times in the

play06:05

past to run a program it first needs to

play06:07

be loaded into memory as that's where

play06:09

the CPU can start fetching instructions

play06:11

and

play06:12

data when loaded into memory the section

play06:14

containing the executable code is known

play06:16

as the text section while data such as

play06:19

Global variables and constant values is

play06:21

loaded into the data section okay I mean

play06:23

he literally just answered the question

play06:25

sorry about that but running a program

play06:27

requires more than these two sections it

play06:29

also need extra space in memory to store

play06:31

all the data generated at runtime like

play06:33

user input and temporary results or

play06:35

variables yeah so he said at runtime

play06:38

like there's going to be separate memory

play06:40

so I don't think he's probably going to

play06:41

have enough time to like go into the

play06:42

details of every little thing in this

play06:44

video but I'll try to add like my

play06:46

commentary which is that so conceptually

play06:49

think about it for a second why would we

play06:51

not have the memory up front for

play06:53

something like a recursive function or

play06:55

even different variables that may or may

play06:57

not necessarily be allocated why do we

play06:59

need like a variable amount of memory

play07:01

because you don't necessarily know you

play07:03

could have a recursive function

play07:04

depending on the input to the program it

play07:06

might stack up 10 times before hitting

play07:08

the base case or depending on a second

play07:10

input it might stack up 20 times if you

play07:12

pre-allocate the memory you don't

play07:14

necessarily know how much memory it's

play07:16

going to take now even the stack is

play07:18

technically Limited in memory that's why

play07:21

like stack Overflow occurs like this

play07:22

region called the stack which recursive

play07:24

functions use it will hit a limit like

play07:26

there is a limit to this I think you can

play07:29

sometimes update that limit many

play07:31

languages will have like a default limit

play07:32

size but anyways we already know a lot

play07:35

about the stack and the Heap such as the

play07:37

fact that they are growing and shrinking

play07:39

in size all the

play07:41

time the tech section is the only one

play07:43

that never change neither in size nor

play07:45

content interesting that would make

play07:48

sense based on like the CPU instructions

play07:50

text is not going to change stack is

play07:51

obviously growing for reasons I talked

play07:53

about not just for recursive functions

play07:55

but also like one function calls another

play07:57

it's going to go on the stack when that

play07:59

function finished it's going to return

play08:00

back to the previous function the Heap I

play08:02

actually don't remember off the top of

play08:04

my head but I'm pretty sure one program

play08:06

if it's using Heap memory the amount of

play08:08

memory that that program is actually

play08:10

using from the Heap could change but

play08:13

theoretically you should be able to use

play08:15

as much memory as your computer has uh

play08:18

for the Heap let me actually just double

play08:19

check that just from our cursory Google

play08:21

search I guess this part is actually AI

play08:23

generated but it does look like a

play08:25

program can use unlimited amounts of

play08:26

Heap memory what's the default stack

play08:29

memory limit in C for example um it

play08:33

looks like it's 1 Megabyte I don't know

play08:35

if that depends on the compiler but

play08:37

again like you can see that this is like

play08:39

relatively small so it's reasonable that

play08:42

you could hit a stack Overflow even if

play08:44

there's not infinite recursion like

play08:46

that's why recursion is actually not

play08:48

good and you're hearing this from me the

play08:50

data structures guy on YouTube that

play08:52

generally speaking you don't want to do

play08:54

recursion even for valid recursion you

play08:56

could hit the memory limit anyways but

play08:59

we can't say the same about the data

play09:00

section because even though it doesn't

play09:02

change in size its content may varies

play09:04

depending on what the running program is

play09:07

doing as you can see so the data region

play09:10

can vary in size I mean if this is part

play09:13

of the executable I wonder if that means

play09:15

that at runtime that that is like the

play09:17

amount of memory that's being used by

play09:19

that data region is going to change but

play09:22

like all that memory should be allocated

play09:24

for the programmer maybe I'm

play09:25

misunderstanding let me just replay it

play09:27

just in case can't say the same about

play09:29

the data section because even though it

play09:30

doesn't change in size its content may

play09:32

varies depending on what the running

play09:34

program is

play09:36

doing as you can see even though

play09:38

initially we loaded the program into

play09:39

memory when running this layout can no

play09:42

longer be considered as a program of

play09:44

course not it has now become a

play09:47

process and please note that this is the

play09:49

memory layout of the process not the

play09:51

process

play09:54

itself the reason this definition is

play09:56

often con that's interesting so that's

play09:58

the memory layout of the process but not

play10:01

the process itself so how do you define

play10:03

a process in my head it's an operating

play10:05

system level unit right like the

play10:06

operating system is managing the process

play10:08

it gives it an ID if there are multiple

play10:10

threads that are a part of that process

play10:12

they will possibly share memory I guess

play10:15

we're getting overly technical let's

play10:16

just continue considered informal is

play10:18

that the notion of what a process is is

play10:20

far too complex to be captured in just a

play10:22

few words we're not going to go into

play10:24

technical details in this video because

play10:26

there's a video about processes already

play10:28

scheduled but for now let me help you

play10:31

get an idea of what a process

play10:35

is consider that little program that

play10:37

comes with your operating system to open

play10:39

text

play10:42

files now imagine we have two files to

play10:44

read if we open both files the operating

play10:47

system will launch the text editor app

play10:49

twice this results in two separate

play10:51

Windows each displaying a different text

play10:55

file both are the same program but two

play10:58

completely different processes

play11:01

right each process has its own memory

play11:03

space of course while the content of the

play11:05

text section in both processes memory is

play11:07

identical since they are the same

play11:09

program the data they are working with

play11:11

is different right so that obviously

play11:14

makes sense and it also makes sense that

play11:16

in a text editor all of the data would

play11:18

be going to the Heap you again wouldn't

play11:20

want to run out of like stack space for

play11:22

that imagine just declaring a massive

play11:24

variable with megabytes like a megabyte

play11:28

long string or something like that

play11:29

probably want to avoid something like

play11:31

that in this example the first process

play11:34

is working with a much larger text file

play11:35

than the second so it naturally requires

play11:38

more memory to manage its

play11:40

data and if you're a casual viewer

play11:43

hopefully that's everything you needed

play11:44

to understand the difference between a

play11:46

program and a

play11:47

process I are we casual viewers I don't

play11:50

feel like I'm a casual viewer I always

play11:52

want to know like the exact details and

play11:53

by the way definitely subscribe to this

play11:55

guy if you're not convinced by now

play11:57

definitely subscribe to this guy Cor

play11:59

dumped I don't want to just call him

play12:00

this guy I actually know him very little

play12:02

uh he's very nice guy he's actually

play12:03

perfectly okay with me reacting to this

play12:05

video I probably should have mentioned

play12:06

that towards the beginning but his

play12:08

channel is just fantastic I could not

play12:10

get enough of it I want to send a

play12:11

special thanks to all of you because we

play12:13

finally surpassed 100,000 subscribers I

play12:16

enjoy learning new things as much as you

play12:18

do in the same way I encourage you to

play12:20

check out brilliant if you're going to

play12:22

get brilliant definitely go to cump's

play12:24

channel and use the link in his

play12:25

description and make sure to support him

play12:27

I emphasize that a program by itself is

play12:29

not a process a program is a passive

play12:31

entity whereas in contrast a process is

play12:34

an active entity although two processes

play12:37

may be associated with the same program

play12:39

they are nevertheless considered two

play12:41

separate execution

play12:42

sequences I know that having a notion of

play12:44

what a process is is not the same as

play12:46

being able to Define it in technical

play12:48

terms but as I mentioned earlier a

play12:50

dedicated video on processes is coming

play12:53

soon this episode is not over though

play12:56

everything I've discussed so far makes

play12:58

sense for compil languages when using

play13:00

languages like C or rust the result of

play13:02

the compilation is an executable file

play13:05

that is the program itself but what

play13:08

about interpreted languages like python

play13:10

or JavaScript where there is no

play13:11

compilation

play13:13

process in Python for example every time

play13:16

we want to run code we must first

play13:18

instruct the computer to run The

play13:19

Interpreter and then one thing I

play13:21

actually want to go back to is he put

play13:23

Java in the same realm as interpreted

play13:26

and so that to me actually does make

play13:29

sense given that like when you're

play13:31

running a piece of java code is it the

play13:33

code that's being executed because for

play13:36

people who don't know Java turns into

play13:37

like bik code and then there's a

play13:38

separate program called the Java virtual

play13:40

machine which then runs that Java code

play13:43

so in a sense I think it is interpreted

play13:45

it really is because what's running is

play13:48

the Java virtual machine at least an

play13:50

instance of it I'm actually not an

play13:52

expert on Java if somebody wants to

play13:53

comment maybe we can answer this

play13:55

ourselves let's use Claude this time and

play13:57

so I asked when a get away when a Java

play14:01

process is running does it get its own

play14:02

instance of the Java virtual machine yes

play14:04

when a Java process is running it

play14:05

typically does so this may or may not be

play14:08

correct I'm going to assume it is

play14:09

because for something basic as this I

play14:11

would think Claude is correct we could

play14:12

also Google this but so that's very

play14:14

interesting so in that sense yeah I mean

play14:16

Java definitely does feel like a

play14:19

interpreted language I don't want to

play14:21

start a debate or anything and in the

play14:22

same realm I actually recently learned

play14:24

this that python is also compiled like

play14:28

there is a compil step like I used to

play14:30

think like I had a very naive

play14:32

understanding of how the python

play14:33

interpreter worked I thought it

play14:34

literally just read the python text

play14:37

files line by line but there is a

play14:39

compilation step so what is the

play14:43

compilation step with python code and

play14:46

how does it differ from java compilation

play14:50

okay so there is a compilation step in

play14:53

Python it's compiled into bite code but

play14:55

it happens at runtime I believe there's

play14:58

not an actual separate compilation step

play15:00

so that honestly makes me feel like you

play15:02

could not know that you could not know

play15:03

that there's a compilation step in Java

play15:06

just like you could ignore like the just

play15:09

in time compilation with JavaScript and

play15:11

you'd probably be fine I'm assuming this

play15:13

is mainly done for optimization reasons

play15:15

was there a point where python did not

play15:19

have a compilation step why does it

play15:22

exist or performance so it sounds like

play15:25

it always was there and mainly does EX

play15:29

for performance reasons or JavaScript

play15:31

where there is no compilation

play15:34

process in Python for example every time

play15:36

we want to run code we must first

play15:38

instruct the computer to run The

play15:40

Interpreter and then tell The

play15:41

Interpreter to execute our

play15:43

code right so every time we run a python

play15:47

file or Python program we're creating a

play15:50

process and that process encapsulates

play15:53

the python interpreter and it's going to

play15:56

specifically be using the file itself

play15:59

self as like the executable as the

play16:01

instruction set not the instruction set

play16:03

as the

play16:04

instructions in other words there are

play16:06

now two passive entities involved the

play16:08

python interpreter which is a program

play16:11

okay right so there's a separate unit

play16:13

running for that process not just the

play16:15

CPU reading like the lowle instructions

play16:18

there are higher level instructions

play16:19

involved file which is practically a

play16:21

text file I would like to highlight here

play16:24

the fact that the python source file is

play16:25

not a program remember that source code

play16:28

is just text that computers cannot

play16:30

understand and therefore cannot execute

play16:32

I guess in this case and maybe I'm

play16:34

getting overly technical but even let's

play16:37

say you took that python file and it

play16:38

turns into bite code the distinction

play16:40

between This and like that c program

play16:43

example we were looking at towards the

play16:44

beginning is I wonder if this python

play16:47

when it's compiled into the bite code in

play16:49

the bite code I wonder if there's a

play16:50

separate region for the data versus like

play16:52

the instructions I mean I wonder if that

play16:54

matters at all but that's just something

play16:56

that came to my mind so in this kind of

play16:57

situations the program we're actually

play16:59

asking the computer to run is The

play17:01

Interpreter not the python code we

play17:04

wrote once this new process is created

play17:07

it has its own memory region with text

play17:09

and data sections right I mean of course

play17:11

every process has a text and data

play17:14

section but I wonder how that relates to

play17:16

like the bik code or like how like the

play17:18

Java virtual machine does it this is

play17:20

from the operating systems perspective

play17:21

but from the python interpretor

play17:23

perspective it's going to be reading

play17:24

like the bik code where's the bik code

play17:26

probably within the text

play17:29

I think I'm just confusing myself maybe

play17:30

they are distinct as well as a stack and

play17:32

a heap just like any other

play17:35

process the key Point here is that

play17:37

what's loaded into the text section is

play17:38

not our python source code but the

play17:40

executable code of The Interpreter our

play17:43

source code is loaded by The Interpreter

play17:45

process into one of its data sections

play17:47

most likely the Heap because it serves

play17:49

as the data The Interpreter will work

play17:51

right that's very interesting so this is

play17:53

the program that's running for it to

play17:55

know how to execute it's going to keep

play17:57

fetching the data from the Heap that's

play18:00

very interesting because still when a

play18:02

program is running it's not just running

play18:05

from top to bottom like there's control

play18:07

flow for example like you might have

play18:09

some instructions but if the if

play18:10

statement does not evaluate to true that

play18:12

if statement is going to be skipped that

play18:14

must mean when you have a python

play18:15

interpreter it's going to go through the

play18:17

memory it's sure it can read through the

play18:19

memory but like that itself needs to be

play18:21

coded to skip certain parts of the code

play18:24

so it's almost like when you're creating

play18:25

an interpreter in a sense you're kind of

play18:27

creating like an abstraction for like a

play18:29

CPU work with to read and

play18:33

interpret and let's wrap it up for now

play18:36

compilers and interpreters deserve their

play18:38

own videos since I'm committed to

play18:40

continue releasing quality content once

play18:42

again I encourage you to subscribe I

play18:44

encourage you guys to subscribe as well

play18:46

honestly his channel is fantastic

Rate This

5.0 / 5 (0 votes)

Связанные теги
program vs processcomputer scienceconcurrencyoperating systemsCPU operationsmemory managementprocess executionearly computersinterpreted languagestechnical deep dive
Вам нужно краткое изложение на английском?