help on using pseudo terminals - using /dev/ptmx

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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.

<code>
#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);
}
</code>
regards,
Kashyap
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[Index of Archives]     [Kernel Newbies]     [Netfilter]     [Bugtraq]     [Photo]     [Stuff]     [Gimp]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Video 4 Linux]     [Linux for the blind]     [Linux Resources]
  Powered by Linux