How do I run a program?

Discussions on more advanced topics such as monolithic vs micro-kernels, transactional memory models, and paging vs segmentation should go here. Use this forum to expand and improve the wiki!
Locked
atomizer
Posts: 4
Joined: Mon Jan 23, 2012 1:39 pm

How do I run a program?

Post by atomizer »

Hi, it's my first post/thread :)

I've made simple os based on Brandon's F. Kernel Dev. Tut. And I have a question. Hoc can I make and run a program for this OS? I've written simple command recognition, to make it easier to do. Does my OS need to be able to read/write files?

The point to run progs. on it to for. ex. make while() func not "freeze" whole system when using for. ex. while(x = 1);

So if you can help me, I want to make code look like this:

Code: Select all

when user sumbits a command {
run_program(command);
}
Sorry for english mistakes(if any :P)
User avatar
piranha
Member
Member
Posts: 1391
Joined: Thu Dec 21, 2006 7:42 pm
Location: Unknown. Momentum is pretty certain, however.
Contact:

Re: How do I run a program?

Post by piranha »

If you want to load executable files and run them, of course it needs to be able to read and write files. It can't magically know what the code for a program is.

Code: Select all

while(x=1);
Will always loop...= != ==

http://wiki.osdev.org/Executable_Formats
Is a good place to start looking. Keep in mind that you're going to want to have a memory manager set up for this to be effective. (paging, a way to malloc() from the OS will make this a lot easier. And then, yes, you'll need to be able to read a file, parse the header and section headers, load the appropriate data into the correct address and then jump to the starting point.

-JL
SeaOS: Adding VT-x, networking, and ARM support
dbittman on IRC, @danielbittman on twitter
https://dbittman.github.io
atomizer
Posts: 4
Joined: Mon Jan 23, 2012 1:39 pm

Re: How do I run a program?

Post by atomizer »

Thanks you. I'll now try to implement file IO. I've actually added malloc(), grow(), free() and realloc(). I'll read more about paging too :)
piranha wrote:

Code: Select all

while(x=1);
Will always loop...= != ==
Yes, but if it is running as a kernel part, you won't be able to write for. ex. But if it will be running in a program, all system processes will be still working.
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re: How do I run a program?

Post by Solar »

atomizer wrote:The point to run progs. on it to for. ex. make while() func not "freeze" whole system when using for. ex. while(x = 1);
That's called "preemption", and you should know stuff like this before doing OS dev.
Every good solution is obvious once you've found it.
atomizer
Posts: 4
Joined: Mon Jan 23, 2012 1:39 pm

Re: How do I run a program?

Post by atomizer »

Solar wrote:
atomizer wrote:The point to run progs. on it to for. ex. make while() func not "freeze" whole system when using for. ex. while(x = 1);
That's called "preemption", and you should know stuff like this before doing OS dev.
:( I can't find anything about this/how to do this :/
User avatar
VolTeK
Member
Member
Posts: 815
Joined: Sat Nov 15, 2008 2:37 pm
Location: The Fire Nation

Re: How do I run a program?

Post by VolTeK »

atomizer wrote:Hi, it's my first post/thread

I've made simple os based on Brandon's F. Kernel Dev. Tut. And I have a question. Hoc can I make and run a program for this OS? I've written simple command recognition, to make it easier to do. Does my OS need to be able to read/write files?

The point to run progs. on it to for. ex. make while() func not "freeze" whole system when using for. ex. while(x = 1);

So if you can help me, I want to make code look like this:
Code:
when user sumbits a command {
run_program(command);
}


Sorry for english mistakes(if any )
Its quite possible that i may be mis reading your goal.. but what your looking for relies in multitasking. I could be wrong but.. load a program, run that program while other program is still in loop... sounds alot like you want multitasking. Have a look online, i could be wrong, but its my guess.
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re: How do I run a program?

Post by Solar »

atomizer wrote: :( I can't find anything about this/how to do this :/
Fail. Find a different hobby.

Seriously.

You just said the equivalent to "I don't really know how a power slide is done or what a 4-wheel-drive is, but I want to become a rallye driver. Can you teach me?".

To which, obviously, the short answer is "no", and the long answer is "I lack the time to teach, and you lack the required knowledge to understand what I could be telling you".

(Hint: Find the thread where we recommend dozens of good books on the subject...)
Every good solution is obvious once you've found it.
atomizer
Posts: 4
Joined: Mon Jan 23, 2012 1:39 pm

Re: How do I run a program?

Post by atomizer »

@GhostXoPCorp Yes, I meant multitasking, I know how to do this. I now understand everything :)

@Solar
Find a different hobby.
Ok, but you change the forum first.

@berkus Thanks, you helped me a lot.
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re: How do I run a program?

Post by Solar »

atomizer wrote:@Solar
Find a different hobby.
Ok, but you change the forum first.
I meant that to be a serious and well-meaning suggestion. You exhibited a serious shortcoming in rather basic knowledge, independent research in the face of rather obvious FAQ / "Search this first" / Forum Rules resources, and - as a latest addition - humor.

Thus, I fear that your current hobby won't make you happy, and seriously suggest you pick something else as a pastime.
Every good solution is obvious once you've found it.
Locked