ipc: add fifo
This commit is contained in:
parent
f56f3842b2
commit
4ec7ff5aaa
9 changed files with 133 additions and 19 deletions
|
|
@ -2,6 +2,8 @@
|
|||
/* shtest: simple userland shell test */
|
||||
#include <stdint.h>
|
||||
|
||||
#define S_IFIFO 0x1000
|
||||
|
||||
typedef int64_t ssize_t;
|
||||
typedef int64_t pid_t;
|
||||
|
||||
|
|
@ -11,6 +13,7 @@ ssize_t write(int fd, void *buf, int count);
|
|||
int close(int fd);
|
||||
pid_t fork();
|
||||
int exit(int status);
|
||||
int mknod(const char *pathname, int mode, int dev);
|
||||
|
||||
void promptfd(int fd)
|
||||
{
|
||||
|
|
@ -19,32 +22,46 @@ void promptfd(int fd)
|
|||
|
||||
void _start()
|
||||
{
|
||||
int fd = open("/dev/tty0", 0);
|
||||
if (fd < 0)
|
||||
int term = open("/dev/tty0", 0);
|
||||
if (term < 0)
|
||||
exit(1);
|
||||
|
||||
promptfd(fd);
|
||||
|
||||
char buf[256];
|
||||
int n;
|
||||
|
||||
/* FIFOs!!!!!!!!! */
|
||||
int r = mknod("/dev/pts", S_IFIFO, 0);
|
||||
int fifofd = open("/dev/pts", 0);
|
||||
if (fifofd < 0)
|
||||
write(term, "open failed\n", 12);
|
||||
|
||||
/* write hello to fifo */
|
||||
int i = write(fifofd, "hello\n", 6);
|
||||
/* read back from fifo */
|
||||
i = read(fifofd, buf, 6);
|
||||
|
||||
/* print output to terminal */
|
||||
write(term, buf, i);
|
||||
promptfd(term);
|
||||
|
||||
/* fork test */
|
||||
pid_t pid = fork();
|
||||
if (pid < 0) {
|
||||
write(fd, "fork failed\n", 12);
|
||||
write(term, "fork failed\n", 12);
|
||||
exit(1);
|
||||
}
|
||||
|
||||
if (pid == 0) {
|
||||
write(fd, "child\n", 6);
|
||||
write(term, "child\n", 6);
|
||||
exit(1);
|
||||
} else {
|
||||
write(fd, "parent\n", 7);
|
||||
write(term, "parent\n", 7);
|
||||
}
|
||||
|
||||
/* rw test */
|
||||
while ((n = read(fd, buf, 256)) > 0) {
|
||||
write(fd, buf, n);
|
||||
while ((n = read(term, buf, 256)) > 0) {
|
||||
write(term, buf, n);
|
||||
|
||||
if(buf[0] == 'q')
|
||||
break;
|
||||
|
|
|
|||
|
|
@ -18,3 +18,4 @@ _sc_define open, 2
|
|||
_sc_define close, 3
|
||||
_sc_define fork, 57
|
||||
_sc_define exit, 60
|
||||
_sc_define mknod, 133
|
||||
|
|
|
|||
Loading…
Reference in a new issue