diff --git a/1c988769-68cd-42e9-a58b-7beecb65cdfd/bin/ps.lua b/1c988769-68cd-42e9-a58b-7beecb65cdfd/bin/ps.lua new file mode 100644 index 0000000..a89093e --- /dev/null +++ b/1c988769-68cd-42e9-a58b-7beecb65cdfd/bin/ps.lua @@ -0,0 +1,25 @@ +local process = require('process') + + +local tree = {['<root>'] = {children = {}}} +local procs = process.list() +for i = 1, procs.n do + local proc = procs[i] + tree[proc.name] = {proc = proc, children = {}} +end +for i = 1, procs.n do + local proc = procs[i] + table.insert(tree[proc.parent or '<root>'].children, tree[proc.name]) +end + +local function show(t, prefix) + if t.proc then + print(string.format('%s - %s: %s', prefix, t.proc.name, t.proc.command)) + prefix = prefix .. ' ' + end + for i = 1, #t.children do + show(t.children[i], prefix) + end +end + +show(tree['<root>'], '') diff --git a/1c988769-68cd-42e9-a58b-7beecb65cdfd/etc/procnames.txt b/1c988769-68cd-42e9-a58b-7beecb65cdfd/etc/procnames.txt new file mode 100644 index 0000000..5bee04c --- /dev/null +++ b/1c988769-68cd-42e9-a58b-7beecb65cdfd/etc/procnames.txt @@ -0,0 +1,1024 @@ +aaron +abigail +abraham +ada +adam +addie +adele +adrian +adriana +adrienne +agnes +aida +aimee +al +alan +albert +alberta +alberto +alejandro +alex +alexander +alexandra +alexis +alfonso +alfred +alfredo +alice +alicia +alisha +alison +allan +allen +allison +alma +alton +alvin +alyssa +amanda +amber +amelia +amy +ana +andre +andrea +andres +andrew +andy +angel +angela +angelica +angelina +angelo +angie +anita +ann +anna +anne +annette +annie +anthony +antoinette +antonia +antonio +april +archie +arlene +armando +arnold +arthur +arturo +ashley +aubrey +audrey +aurora +austin +barbara +barry +beatrice +becky +belinda +ben +benjamin +bennie +benny +bernadette +bernard +bernice +bertha +bessie +beth +bethany +betsy +bettie +betty +beulah +beverly +bill +billie +billy +blake +blanca +blanche +bob +bobbie +bobby +bonita +bonnie +brad +bradley +brandi +brandon +brandy +brenda +brent +brett +brian +bridget +brittany +brittney +brooke +bruce +bryan +bryant +byron +caitlin +caleb +calvin +cameron +camille +candace +candice +cara +carl +carla +carlos +carlton +carmen +carol +carole +caroline +carolyn +carrie +carroll +cary +casey +cassandra +cassie +catherine +cathy +cecelia +cecil +cecilia +cedric +celeste +celia +cesar +chad +charlene +charles +charlie +charlotte +chelsea +cheri +cheryl +chester +chris +christa +christian +christie +christina +christine +christopher +christy +cindy +claire +clara +clarence +clark +claude +claudia +clayton +cleo +clifford +clifton +clint +clinton +clyde +cody +colin +colleen +connie +constance +cora +corey +corinne +cory +courtney +craig +cristina +crystal +curtis +cynthia +daisy +dale +dallas +damon +dan +dana +daniel +danielle +danny +darla +darlene +darrel +darrell +darren +darryl +daryl +dave +david +dawn +dean +deanna +debbie +debora +deborah +debra +delbert +delia +della +delores +deloris +dena +denise +dennis +derek +derrick +desiree +devin +dewey +diana +diane +dianna +dianne +dina +dixie +dolores +dominic +dominique +don +donald +donna +donnie +dora +doreen +doris +dorothy +dorthy +doug +douglas +doyle +drew +duane +dustin +dwayne +dwight +earl +earnest +ebony +ed +eddie +edgar +edith +edmund +edna +eduardo +edward +edwin +effie +eileen +elaine +elbert +eleanor +elena +elias +elisa +elisabeth +elizabeth +ella +ellen +ellis +elmer +eloise +elsa +elsie +elva +elvira +emily +emma +enrique +eric +erica +erick +erik +erika +erin +erma +ernest +ernestine +ernesto +ervin +essie +estella +estelle +esther +ethel +etta +eugene +eugenia +eula +eunice +eva +evan +evelyn +everett +faith +fannie +faye +felicia +felipe +felix +fern +fernando +flora +florence +floyd +forrest +frances +francine +francis +francisca +francisco +frank +frankie +franklin +fred +freda +freddie +frederick +fredrick +gabriel +gail +gale +garrett +garry +gary +gayle +gene +geneva +genevieve +geoffrey +george +georgia +gerald +geraldine +gerard +gerardo +gertrude +gilbert +gilberto +gina +ginger +gladys +glen +glenda +glenn +gloria +goldie +gordon +grace +grant +greg +gregg +gregory +gretchen +guadalupe +guillermo +gustavo +guy +gwen +gwendolyn +hannah +harold +harriet +harry +harvey +hattie +hazel +heather +hector +heidi +helen +helene +henrietta +henry +herbert +herman +hilda +holly +homer +hope +horace +howard +hubert +hugh +hugo +ian +ida +ignacio +ina +inez +ingrid +ira +irene +iris +irma +irving +isaac +isabel +ismael +israel +iva +ivan +jack +jackie +jacob +jacqueline +jacquelyn +jaime +jake +james +jamie +jan +jana +jane +janelle +janet +janette +janice +janie +janis +jared +jasmine +jason +javier +jay +jean +jeanette +jeanne +jeannette +jeannie +jeff +jeffery +jeffrey +jenifer +jenna +jennie +jennifer +jenny +jeremiah +jeremy +jermaine +jerome +jerry +jesse +jessica +jessie +jesus +jewel +jewell +jill +jim +jimmie +jimmy +jo +joan +joann +joanna +joanne +jodi +jody +joe +joel +joey +johanna +john +johnathan +johnnie +johnny +jon +jonathan +jonathon +jordan +jorge +jose +josefina +joseph +josephine +josh +joshua +josie +joy +joyce +juan +juana +juanita +judith +judy +julia +julian +julie +julio +julius +june +justin +kara +karen +kari +karin +karl +karla +kate +katherine +kathleen +kathryn +kathy +katie +katrina +kay +kayla +keith +kelley +kelli +kellie +kelly +kelsey +kelvin +ken +kendra +kenneth +kenny +kent +kerri +kerry +kevin +kim +kimberly +kirk +kris +krista +kristen +kristi +kristie +kristin +kristina +kristine +kristopher +kristy +krystal +kurt +kyle +lana +lance +larry +latasha +latonya +latoya +laura +laurel +lauren +laurence +laurie +laverne +lawrence +leah +lee +leigh +lela +leland +lena +lenora +leo +leon +leona +leonard +leroy +lesley +leslie +lester +leticia +levi +lewis +lila +lillian +lillie +linda +lindsay +lindsey +lionel +lisa +lloyd +lois +lola +lonnie +lora +loren +lorena +lorene +lorenzo +loretta +lori +lorna +lorraine +lottie +lou +louis +louise +lourdes +lowell +lucas +lucia +lucille +lucinda +lucy +luis +luke +lula +lupe +luther +luz +lydia +lyle +lynda +lynette +lynn +lynne +mabel +mable +mack +madeline +mae +maggie +malcolm +mamie +mandy +manuel +marc +marcella +marcia +marco +marcos +marcus +margaret +margarita +margie +marguerite +maria +marian +marianne +marie +marilyn +marina +mario +marion +marissa +marjorie +mark +marla +marlene +marsha +marshall +marta +martha +martin +marty +marvin +mary +maryann +mathew +matt +matthew +mattie +maude +maureen +maurice +max +maxine +may +megan +meghan +melanie +melba +melinda +melissa +melody +melvin +mercedes +meredith +merle +michael +micheal +michele +michelle +miguel +mike +mildred +milton +mindy +minnie +miranda +miriam +misty +mitchell +molly +mona +monica +monique +morgan +morris +muriel +myra +myrna +myron +myrtle +nadine +nancy +naomi +natalie +natasha +nathan +nathaniel +neal +neil +nellie +nelson +nettie +nicholas +nichole +nick +nicolas +nicole +nikki +nina +noah +noel +nora +norma +norman +olga +olive +oliver +olivia +ollie +omar +opal +ora +orlando +orville +oscar +otis +owen +pablo +pam +pamela +pat +patrice +patricia +patrick +patsy +patti +patty +paul +paula +paulette +pauline +pearl +pedro +peggy +penny +perry +pete +peter +philip +phillip +phyllis +polly +preston +priscilla +rachael +rachel +rafael +ralph +ramiro +ramon +ramona +randall +randolph +randy +raquel +raul +ray +raymond +reba +rebecca +rebekah +regina +reginald +rena +rene +renee +rex +rhonda +ricardo +richard +rick +rickey +ricky +rita +robbie +robert +roberta +roberto +robin +robyn +rochelle +roderick +rodney +rodolfo +rogelio +roger +roland +ron +ronald +ronda +ronnie +roosevelt +rosa +rosalie +rosario +rose +rosemarie +rosemary +rosetta +rosie +ross +roxanne +roy +ruben +ruby +rudolph +rudy +rufus +russell +ruth +ryan +sabrina +sadie +sallie +sally +salvador +salvatore +sam +samantha +sammy +samuel +sandra +sandy +santiago +santos +sara +sarah +scott +sean +sergio +seth +shane +shannon +shari +sharon +shaun +shawn +shawna +sheila +shelby +sheldon +shelia +shelley +shelly +sheri +sherman +sherri +sherrie +sherry +sheryl +shirley +sidney +silvia +simon +sonia +sonja +sonya +sophia +sophie +spencer +stacey +stacie +stacy +stanley +stella +stephanie +stephen +steve +steven +stewart +stuart +sue +susan +susie +suzanne +sylvester +sylvia +tabitha +tamara +tami +tamika +tammie +tammy +tanya +tara +tasha +taylor +ted +terence +teresa +teri +terrance +terrence +terri +terry +thelma +theodore +theresa +therese +thomas +tiffany +tim +timothy +tina +toby +todd +tom +tomas +tommie +tommy +toni +tony +tonya +tracey +traci +tracie +tracy +travis +trevor +tricia +trina +trisha +troy +tyler +tyrone +valerie +van +vanessa +velma +vera +verna +vernon +veronica +vicki +vickie +vicky +victor +victoria +vincent +viola +violet +virgil +virginia +vivian +wade +wallace +walter +wanda +warren +wayne +wendell +wendy +wesley +whitney +wilbert +wilbur +wilfred +willard +william +willie +willis +wilma +wilson +winifred +wm +woodrow +yolanda +yvette +yvonne +zachary diff --git a/1c988769-68cd-42e9-a58b-7beecb65cdfd/lib/process.lua b/1c988769-68cd-42e9-a58b-7beecb65cdfd/lib/process.lua index 3ed63c4..9f8df3c 100644 --- a/1c988769-68cd-42e9-a58b-7beecb65cdfd/lib/process.lua +++ b/1c988769-68cd-42e9-a58b-7beecb65cdfd/lib/process.lua @@ -5,6 +5,67 @@ local process = {} local running = setmetatable({}, {__mode="k"}) local coroutine_create = coroutine.create +local function newName() + local f, reason = io.open('/etc/procnames.txt') + if not f then + error(reason) + end + local extant = {} + for _, proc in pairs(running) do + extant[proc.name] = true + end + local lineno = 1 + local ret + while true do + local line = f:read() + if not line then + break + end + if not extant[line] then + if math.random(lineno) == 1 then + ret = line + end + lineno = lineno + 1 + end + end + if not ret then + error('no process names available') + end + return ret +end + +local function processForUserConsumption(self) + local ret = { + path = self.path, + env = self.env, + command = self.command, + data = self.data, + name = self.name, + } + if self.parent then + ret.parent = self.parent.name + end + return ret +end + +local function addProcess(co, parent, path, command, env) + local data = {} + if parent then + data = setmetatable(data, {__index=parent.data}) + end + running[co] = { + path = path, + command = command, + env = env, + parent = parent, + data = data, + instances = setmetatable({}, {__mode="v"}), + name = newName(), + userConsumable = processForUserConsumption, + } + return co +end + local function findProcess(co) co = co or coroutine.running() for main, process in pairs(running) do @@ -65,17 +126,27 @@ function process.load(path, env, init, name) end return code(...) end) - running[thread] = { - path = path, - command = name, - env = env, - data = setmetatable({}, {__index=process and process.data or nil}), - parent = process, - instances = setmetatable({}, {__mode="v"}) - } + addProcess(thread, process, path, name, env) return thread end +function process.spawn(f, env, name, path) + checkArg(1, f, "function") + checkArg(2, env, "table", "nil") + checkArg(3, name, "string", "nil") + checkArg(4, path, "string", "nil") + + local process = findProcess() + if process then + env = env or process.env + end + if not path then + path = '<function>' + end + env = setmetatable({}, {__index=env or _G}) + return addProcess(coroutine_create(f), process, path, name, env) +end + function process.running(level) -- kept for backwards compat, prefer process.info local info = process.info(level) if info then @@ -96,10 +167,19 @@ function process.info(levelOrThread) end end if process then - return {path=process.path, env=process.env, command=process.command, data=process.data} + return process:userConsumable() end end +function process.list() + local ret = {n = 0} + for _, proc in pairs(running) do + ret.n = ret.n + 1 + ret[ret.n] = proc:userConsumable() + end + return ret +end + function process.install(path, name) _G.coroutine.create = function(f) local co = coroutine_create(f) @@ -111,14 +191,7 @@ function process.install(path, name) env = env or select(2, process.running()) return load(ld, source, mode, env) end - local thread = coroutine.running() - running[thread] = { - path = path, - command = name, - env = _ENV, - data = {}, - instances = setmetatable({}, {__mode="v"}) - } + addProcess(coroutine.running(), nil, path, name, _ENV) end -return process \ No newline at end of file +return process