144 lines
3.0 KiB
C++
144 lines
3.0 KiB
C++
#include "../libsys/stub.h"
|
|
#include "../libsys/string.h"
|
|
|
|
char sbuf[8194], rbuf[8194]; // (2 * 4KiB) + 2
|
|
|
|
void main() {
|
|
fork();
|
|
fork();
|
|
int ppid = sys_getpid();
|
|
int other = fork();
|
|
//write(1, "app", 3, 0, ppid);
|
|
if (ppid == other) { // child
|
|
sbuf[0] = 3;
|
|
sbuf[8192] = sys_getpid();
|
|
sbuf[8193] = 1;
|
|
send(other, sbuf, 8193, rbuf, 8193);
|
|
|
|
char msg[] = "REPLY: AA\n";
|
|
msg[7] += rbuf[0] + sbuf[8193];
|
|
msg[8] += 4 + ppid;
|
|
write(0, msg, 10,0, ppid);
|
|
} else { // parent
|
|
receive(rbuf, 8193);
|
|
rbuf[0] = rbuf[0] + rbuf[8192];
|
|
rbuf[8193] = 7;
|
|
reply(rbuf, 8193);
|
|
}
|
|
|
|
sys_exit();
|
|
}
|
|
//// vim: set noet ts=4 sw=4:
|
|
//
|
|
//#include "../libsys/stub.h"
|
|
//#include "../libsys/string.h"
|
|
//
|
|
//char* itoh(unsigned int value, char* buffer) {
|
|
// char* ptr = &buffer[11];
|
|
// *ptr = '\0'; // Nullterminator am Ende setzen
|
|
//
|
|
// if (value == 0) {
|
|
// *--ptr = '0';
|
|
// return ptr;
|
|
// }
|
|
//
|
|
// do {
|
|
// ptr--;
|
|
// *ptr = '0' + (value % 16);
|
|
// if(*ptr >= 0x3A)
|
|
// *ptr+=7;
|
|
// value /= 16;
|
|
// } while (value != 0);
|
|
//
|
|
// return ptr;
|
|
//}
|
|
//char* itoa(unsigned int value, char* buffer) {
|
|
// char* ptr = &buffer[11];
|
|
// *ptr = '\0'; // Nullterminator am Ende setzen
|
|
//
|
|
// if (value == 0) {
|
|
// *--ptr = '0';
|
|
// return ptr;
|
|
// }
|
|
//
|
|
// do {
|
|
// ptr--;
|
|
// *ptr = '0' + (value % 10);
|
|
// value /= 10;
|
|
// } while (value != 0);
|
|
//
|
|
// return ptr;
|
|
//}
|
|
//
|
|
//extern "C" void main() {
|
|
// // Thread 1 may be an auxiliary thread
|
|
//
|
|
// //sys_test(1,2,3,4,5);
|
|
//
|
|
// uint8_t ret = fork();
|
|
// ret = fork();
|
|
//
|
|
// unsigned id = sys_getpid();
|
|
//
|
|
// char text[] = "appX";
|
|
// text[3] = 0x30+id;
|
|
// write(1, text, strlen(text), 0, (int)id);
|
|
//
|
|
// char msg[] = "forked pid: ";
|
|
// msg[12] = 0x30+ret;
|
|
// write(1, msg, strlen(msg), 6, (int)id);
|
|
//
|
|
// uint8_t cnt = 0;
|
|
//
|
|
// while(1){
|
|
// cnt = (cnt+1)%100;
|
|
// char msg[12];
|
|
// char* num = itoa(cnt, msg);
|
|
// write(1, num, strlen(num), 25, (int)id);
|
|
// sleep(100);
|
|
// }
|
|
//
|
|
//
|
|
// for (uint8_t i = 1;; ++i) {
|
|
// //counter to see app running
|
|
// cnt=(cnt+1)%100;
|
|
// char buf[32];
|
|
// char* msg = itoa(cnt,buf);
|
|
// write(1, msg, strlen(msg), 6, (int)id);
|
|
//
|
|
// //test ipc
|
|
// if((i+50)%100 == 0){
|
|
// if(id == 2){
|
|
// char txt[] = "toastbrot ";
|
|
// itoa(cnt, &txt[1]);
|
|
// write(2, "send\n", 5);
|
|
// send(4, txt, strlen(txt), txt, 15);
|
|
// write(1, txt, strlen(txt), 25, (int)id);
|
|
// }
|
|
// }
|
|
// if(i%100 == 0){
|
|
// if(id == 4){
|
|
// char blubb[20];
|
|
// if(receive(blubb, sizeof(blubb))){
|
|
// write(1, blubb, strlen(blubb), 25, (int)id);
|
|
// write(2, "reply\n", 6);
|
|
// memset(&blubb[10], ' ', 3);
|
|
// itoa(cnt, &blubb[1]);
|
|
// reply(blubb, sizeof(blubb));
|
|
// }
|
|
// }
|
|
// }
|
|
//
|
|
// // test map/unmap and print ptr
|
|
// void* ptr= map(4096);
|
|
// uint16_t* val = ((uint16_t*)ptr);
|
|
// *val = 0x1337;
|
|
//
|
|
// msg = itoh((uintptr_t)ptr,buf);
|
|
// write(1, msg, strlen(msg), 12, (int)id);
|
|
// unmap(ptr, 4096);
|
|
//
|
|
// sleep(100);
|
|
// }
|
|
//}
|