Skip to contentSkip to conversation

help on using pseudo terminals - using /dev/ptmx

DISCUSSION C K Kashyap 1 participant 1 message May 25, 2006

lore
Share & tools
lore
#0 lore raw

Hi all,

I recently ran into trouble with pseudo terminals while trying to make nxterm(microwindows or nano X) work.

Could someone please help me out with the program below...where I am trying to do a two way communication between parent and child using pseudo-terminal.

#include <pty.h>
#include <utmp.h>
#include <fcntl.h>
#include <stdio.h>

int main(){
int amaster,aslave;
char name[256];
char buffer[20];

openpty(&amaster,&aslave,name,NULL,NULL);
fcntl (amaster, F_SETFL, O_NONBLOCK);
fcntl (aslave, F_SETFL, O_NONBLOCK);

printf("Master = %d, Slave = %d\n",amaster,aslave); printf("NAME %s\n",name);

if(fork()==0){
//login_tty(aslave);
read(aslave,buffer,10);
printf("Child: %s\n",buffer);
write(aslave,"ABCDEFGHIJ\n",11);
sleep(5);
exit(0);

}
// login_tty(amaster);
write(amaster,"1234567890\n",11);
read(amaster,buffer,10);
printf("Parent: %s\n",buffer);

sleep(5);
}

Signature · 2 lines
Regards,
Kashyap