caucow

sendstop

Dec 28th, 2016 (edited)
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.83 KB | None | 0 0
  1. multishell.setTitle(multishell.getCurrent(), "stop")
  2. local m = peripheral.find("modem")
  3. local senderID = os.getComputerLabel() == nil and "ID:" .. os.getComputerID() or os.getComputerLabel()
  4. local channels = {
  5.       ["stdout"] = 1000,
  6.       ["stdin"] = 1001,
  7.       ["witherout"] = 1010,
  8.       ["witherin"] = 1011
  9.     }
  10. local receiver = ...
  11.  
  12. local function sendCmd(program, cmd, ...)
  13.   m.transmit(channels.stdin, channels.stdout,
  14.       {
  15.           ["program"] = program,
  16.           ["type"] = "cmd",
  17.           ["cmd"] = cmd,
  18.           ["text"] = {...},
  19.           ["sender"] = senderID,
  20.           ["receiver"] = receiver
  21.       })
  22. end
  23.  
  24. print("Sending SIGTERM for 3 sec.")
  25. local eTime = os.clock() + 3
  26. while os.clock() < eTime do
  27.   sendCmd("control", "sigterm")
  28.   os.startTimer(0)
  29.   os.pullEvent("timer")
  30. end
  31. shell.switchTab(1)
Add Comment
Please, Sign In to add comment