Jump to content
  • Sky
  • Blueberry
  • Slate
  • Blackcurrant
  • Watermelon
  • Strawberry
  • Orange
  • Banana
  • Apple
  • Emerald
  • Chocolate
  • Charcoal
  • 0
XanderRadio

Multi program server for base

Question

i am making a server for my modded base on a server and i need it to be able to run several programs at once so that i can control multiple things at the same time, i would like to be able to also create new programs and modify code without interrupting the other programs running on the server. if this is possible please help, try to make the solution as simple and explainable as you can as i am rather new to open computers coding as far as crazy advanced stuff goes so try to make it have as few lines and variables as possible...

thanks in advance, XanderRadio

Link to post
Share on other sites

2 answers to this question

Recommended Posts

  • 0

What you're looking for are daemons/services.

These are programs that run in the background while your gui is available in the foreground for you to use as normal.

Trouble is, they're kinda complex :P it took me far too long to understand how to use them!

 

Simpler solutions could be turning all of your functions into separate lua scripts and having a central program execute them one by one, round robin style.

As long as the scripts don't take too long, this would probably serve your purpose.

 

Of course if you want proper multithreading (i.e. running everything at once) then simply use multiple computers and you'll find a good deal of the technical issues just melt away.

Of course that solution isn't the cheapest...

Link to post
Share on other sites
  • 0

I would agree with your first statement. Daemons/services are probably the route to go, but don't forget OpenOS has threads which can be handy too. Services are pretty dang simple though.. The only real requirement is that you have a start and stop method, any other method is optional. You can check out the example service in /etc/rc.d/example.lua but note that there is only a start method and the 'service' isn't very compelling as to possible uses. I think an easy mix is with services that spawn threads. i.e. A service that can manage other processes by launching and killing them with service methods. Here's a (hopefully) simple and understandable service..

/etc/rc.d/testservice.lua

local event = require "event"
local shell = require "shell"
local thread = require "thread"

local threads = {}

-- # Service methods (notice they aren't local variables. That makes them service methods)

function start(prog, ...)
  -- # start a program as a thread process.
  local proc = thread.create(shell.execute, prog, os.getenv("shell"), ...)
  -- # detach it from current process so rc doesn't block the main thread when we start.
  proc:detach()
  -- # keep track of started processes
  table.insert(threads, proc)
end

function stop()
  -- # kill all not 'dead' threads service started
  for i, proc in ipairs(threads) do
    if proc.status and proc:status() ~= "dead" then
      proc:kill() -- # stabby stab...
    end
  end
end

Use like so..  `rc testservice start myprogram args...`

Hope this gives you some ideas. Feel free to ask questions :3

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use and Privacy Policy.