Path: utzoo!attcan!uunet!husc6!purdue!i.cc.purdue.edu!j.cc.purdue.edu!ain From: ain@j.cc.purdue.edu (Patrick White) Newsgroups: comp.sources.amiga Subject: eps & stp (sources) Keywords: eps, stp, process status, set task priority Message-ID: <7228@j.cc.purdue.edu> Date: 10 Jun 88 23:00:36 GMT Organization: PUCC Land, USA Lines: 237 Approved: ain@j.cc.purdue.edu (Patrick White) Submitted by: jeff@novavax (Jeffrey Bailey) Summary: eps -- extended process status, stp -- set task priority Poster Boy: Patrick White (ain@j.cc.purdue.edu) Archive Name: sources/amiga/volume5/eps-stp.s.sh.Z Tested but not compiled. NOTES: This contains two relates programs -- eps which prints out what processes are running and their priorties, and stp which sets the task priorities. I redid the shar to separate docs, sources, and binaries. -- Pat White (co-moderator comp.sources/binaries.amiga) ARPA/UUCP: j.cc.purdue.edu!ain BITNET: PATWHITE@PURCCVM PHONE: (317) 743-8421 U.S. Mail: 320 Brown St. apt. 406, West Lafayette, IN 47906 [How do you get to heaven? Go to Pluto and hang a left.] ======================================== # This is a shell archive. # Remove everything above and including the cut line. # Then run the rest of the file through sh. #----cut here-----cut here-----cut here-----cut here----# #!/bin/sh # shar: Shell Archiver # Run the following text with /bin/sh to create: # README # stp.c # This archive created: Fri Jun 3 12:15:08 1988 # By: Patrick White (PUCC Land, USA) echo shar: extracting README '(377 characters)' cat << \SHAR_EOF > README I did not include the C source to the eps utility, for the simple reason that I extensively used routines from my personal library in this program. It would be more effort than it is worth to extract the specific sources used from my library. Without these library routines, the source to eps is virtually useless. I hope you find these utilities of some use. --Jeff SHAR_EOF if test 377 -ne "`wc -c README`" then echo shar: error transmitting README '(should have been 377 characters)' fi echo shar: extracting stp.c '(4901 characters)' cat << \SHAR_EOF > stp.c #include #include #include #include #include #include #include #include #include #include /* Program: stp.c (Set Task Priority) Purpose: Change a currently existing task's priority. Author: Jeffrey Bailey Date: 3/15/88 Usage: stp Compiler: Lattice C 4.0 Porting: It should be relatively easy to modify this to work with Aztec C. The only special routine I used was strtol(), which may or may not exist in Aztec. I release this program into the public domain. You may use all or part of the source code for any purpose whatsoever. All I ask is that you give credit where credit is due. I do not guarantee this program in any way, shape, or form. Note that it does work for me, and I have attempted to test it thoroughly. Use it at your own risk. You can report any bugs, problems, features, suggestions, etc. to the address below. I do not promise to change or fix anything, but I will try to respond to any mail messages I receive - please include a good return path in your message! UUCP:...{ihnp4!codas, ucf-cs, allegra}!novavax!jeff UUCP:...{ihnp4!codas, ucf-cs, allegra}!novavax!regulus!jeff (Private) (routing through codas preferred) */ struct ExecBase *ExecBase; void main(argc, argv) int argc; char *argv []; { char *badchar; struct Task *tad; long tpri; int saneaddr; /* If started from WorkBench, exit. Don't bother printing an error msg. */ if(argc == 0) exit(20); if(argc < 3) { puts("STP: Missing args. Supply a task address and a priority."); exit(20); } if(argc > 3) { puts("STP: Too many args. Supply a task address and a priority."); } /* Convert hex string to a pointer value. If strtol() sets badchar to point to a NULL, then conversion went ok. Otherwise, badchar points at char in error. */ tad = (struct Task *) strtol(argv [1], &badchar, 16); if(*badchar != NULL) { puts("STP: Bad hex string conversion on task address."); exit(20); } /* Convert decimal string to an integer value. If strtol() sets badchar to point to a NULL, then conversion went ok. Otherwise, badchar points at char in error. */ tpri = strtol(argv [2], &badchar, 10); if(*badchar != NULL) { puts("STP: Bad decimal string conversion on task priority."); exit(20); } /* Check priority to make sure it's within proper bounds. */ if(tpri < -128) { puts("STP: Priority specified is too low. Must be no less than -128."); exit(20); } if(tpri > 127) { puts("STP: Priority specified is too high. Must be no greater than 127."); exit(20); } /* Get ExecBase pointer. We need this to do sanity checking on the TCB address supplied. */ if( (ExecBase = (struct ExecBase *) OpenLibrary("exec.library",0)) == 0 ) { puts("STP: Couldn't open Exec Library."); exit(20); } /* Disable interrupts. The RKM says this is necessary when scanning exec lists. Apparently Forbid() isn't good enough in this instance. */ Disable(); /* Do our TCB address sanity checking. Set the new task priority if the address is valid. */ if( (saneaddr = sane_address(tad)) ) { SetTaskPri(tad, tpri); } /* Enable interrupts again. */ Enable(); /* If we couldn't find the TCB, complain. Can't do this inside the Disable() Enable() pair, 'cause we can't keep interrupts disabled for very long, plus the RKM warns against printing when you disable interrupts. */ if(!saneaddr) { puts("STP: Can't find TCB at specified address."); } exit(0); } sane_address(taskaddr) register struct Task *taskaddr; { register struct Task *task; /* Check to see if we're trying to modify the current task's priority. */ if(taskaddr == ExecBase->ThisTask) return(1); /* Check the ready queue for our TCB. */ for(task = (struct Task *)ExecBase->TaskReady.lh_Head; task->tc_Node.ln_Succ; task = (struct Task *)task->tc_Node.ln_Succ) { if(task == taskaddr) return(1); } /* Check the wait queue for our TCB. */ for(task = (struct Task *)ExecBase->TaskWait.lh_Head; task->tc_Node.ln_Succ; task = (struct Task *)task->tc_Node.ln_Succ) { if(task == taskaddr) return(1); } /* If we got to this point, we haven't found our TCB. Return failure. */ return(0); } SHAR_EOF if test 4901 -ne "`wc -c stp.c`" then echo shar: error transmitting stp.c '(should have been 4901 characters)' fi # End of shell archive exit 0