I am trying to work with " Introduction to interprocess communication using named pipes - full duplex communication using named pipes ", link ; in particular fd_server.c(see below for reference)
Here is my info and compilation line:
: ~ $ cat / etc / issue
Ubuntu 10.04 LTS \ n \ l
: ~ $ gcc --version
gcc (Ubuntu 4.4.3-4ubuntu5) 4.4.3
: ~ $ gcc fd_server.c -o fd_server
fd_server.ccreates two named pipes: one for reading and one for writing. What can be done is: in one terminal, start the server and read (through cat) your write channel:
: ~ $ ./fd_server & 2> / dev / null
[1] 11,354
: ~ $ cat / tmp / np2
and in another, write (using the echo) to the server’s read channel:
: ~ $ echo "heeellloooo"> / tmp / np1
Returning to the first terminal, you can see:
: ~ $ cat / tmp / np2
HEEELLLOOOO
0 [1] + Exit 13 ./fd_server 2> / dev / null
, "" ( "" ) ; , cat echo - . , screen /dev/ttyS0 38400, , , , /dev/ttyS0, . , , screen, , , , screen .
"" ( /)?
:
#include <stdio.h>
#include <errno.h>
#include <ctype.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#define NP1 "/tmp/np1"
#define NP2 "/tmp/np2"
#define MAX_BUF_SIZE 255
#include <stdlib.h> //exit
#include <string.h> //strlen
int main(int argc, char *argv[])
{
int rdfd, wrfd, ret_val, count, numread;
char buf[MAX_BUF_SIZE];
ret_val = mkfifo(NP1, 0666);
if ((ret_val == -1) && (errno != EEXIST)) {
perror("Error creating the named pipe");
exit (1);
}
ret_val = mkfifo(NP2, 0666);
if ((ret_val == -1) && (errno != EEXIST)) {
perror("Error creating the named pipe");
exit (1);
}
rdfd = open(NP1, O_RDONLY);
wrfd = open(NP2, O_WRONLY);
numread = read(rdfd, buf, MAX_BUF_SIZE);
buf[numread] = '0';
fprintf(stderr, "Full Duplex Server : Read From the pipe : %sn", buf);
count = 0;
while (count < numread) {
buf[count] = toupper(buf[count]);
count++;
}
write(wrfd, buf, strlen(buf));
}
Edit:
, - , , - , - script ( " , script ..." ) :
( ./fd_server 2>/dev/null; )&
bgPidS=$!
( cat < /tmp/np2 ; )&
bgPid=$!
echo $(kill -0 $bgPidS 2>/dev/null ; echo $?)
while [ "$(kill -0 $bgPidS 2>/dev/null ; echo $?)" -eq "0" ] && read cmd; do
echo "$? - $bgPidS - $bgPid" >&2
echo "$cmd"
echo -e "\nproc: $(kill -0 $bgPidS 2>/dev/null ; echo $?)" >&2
done >/tmp/np1
echo OUT
if [ "$(kill -0 $bgPid 2>/dev/null ; echo $?)" -eq "0" ] ;
then
kill $bgPid
fi
if [ "$(kill -0 $bgPidS 2>/dev/null ; echo $?)" -eq "0" ] ;
then
kill $bgPidS
fi
, script, starter.sh , :
$ ./starter.sh
0
i'm typing here and pressing [enter] at end
0 - 13496 - 13497
I'M TYPING HERE AND PRESSING [ENTER] AT END
0~ .N= ( ~ } @ ~ [garble]
proc: 0
OUT
" " ( ) - , ; (, , , script). , , , ( , - , stty raw , : Enter, Ctrl - C:))
, ( screen , ), "" "", ; , , / "", .