diff options
author | Freya Murphy <freya@freyacat.org> | 2025-04-21 16:45:28 -0400 |
---|---|---|
committer | Freya Murphy <freya@freyacat.org> | 2025-04-21 16:45:33 -0400 |
commit | ceb9471fed96f907e37a6ba031825c31167a8ff4 (patch) | |
tree | d98392e420b4541a6ba926ff4d8b3ebe85734580 /user/progI.c | |
parent | update linker scripts (diff) | |
download | comus-ceb9471fed96f907e37a6ba031825c31167a8ff4.tar.gz comus-ceb9471fed96f907e37a6ba031825c31167a8ff4.tar.bz2 comus-ceb9471fed96f907e37a6ba031825c31167a8ff4.zip |
update userland to compile
Diffstat (limited to '')
-rw-r--r-- | user/progI.c | 107 |
1 files changed, 0 insertions, 107 deletions
diff --git a/user/progI.c b/user/progI.c deleted file mode 100644 index a1988e3..0000000 --- a/user/progI.c +++ /dev/null @@ -1,107 +0,0 @@ -#include <common.h> - -#ifndef MAX_CHILDREN -#define MAX_CHILDREN 50 -#endif - -/** -** User function I: exit, fork, exec, kill, sleep, waitpid, write -** -** Reports, then loops spawing userW, sleeps, kills two children, then -** loops checking the status of all its children -** -** Invoked as: userI [ x [ n ] ] -** where x is the ID character (defaults to 'i') -** n is the number of children to spawn (defaults to 5) -*/ - -USERMAIN(main) -{ - int count = 5; // default child count - char ch = 'i'; // default character to print - int nap = 5; // nap time - char buf[128]; - char ch2[] = "*?*"; - uint_t children[MAX_CHILDREN]; - int nkids = 0; - - // process the command-line arguments - switch (argc) { - case 3: - count = str2int(argv[2], 10); - // FALL THROUGH - case 2: - ch = argv[1][0]; - break; - case 1: // just use the defaults - break; - default: - sprint(buf, "userI: argc %d, args: ", argc); - cwrites(buf); - for (int i = 0; i <= argc; ++i) { - sprint(buf, " %s", argv[argc] ? argv[argc] : "(null)"); - cwrites(buf); - } - cwrites("\n"); - } - - // secondary output (for indicating errors) - ch2[1] = ch; - - // announce our presence - write(CHAN_SIO, &ch, 1); - - // set up the argument vector - // we run: userW 10 5 - - char *argsw[] = { "userW", "W", "10", "5", NULL }; - - for (int i = 0; i < count; ++i) { - int whom = spawn(ProgW, argsw); - if (whom < 0) { - swrites(ch2); - } else { - swritech(ch); - children[nkids++] = whom; - } - } - - // let the children start - sleep(SEC_TO_MS(nap)); - - // kill two of them - int32_t status = kill(children[1]); - if (status) { - sprint(buf, "!! %c: kill(%d) status %d\n", ch, children[1], status); - cwrites(buf); - children[1] = -42; - } - status = kill(children[3]); - if (status) { - sprint(buf, "!! %c: kill(%d) status %d\n", ch, children[3], status); - cwrites(buf); - children[3] = -42; - } - - // collect child information - while (1) { - int n = waitpid(0, NULL); - if (n == E_NO_CHILDREN) { - // all done! - break; - } - for (int i = 0; i < count; ++i) { - if (children[i] == n) { - sprint(buf, "== %c: child %d (%d)\n", ch, i, children[i]); - cwrites(buf); - } - } - sleep(SEC_TO_MS(nap)); - }; - - // let init() clean up after us! - - exit(0); - - return (42); // shut the compiler up! -} |