Terminal emulator issue

Linux specific questions.
Posts: 148
Joined: May 29, 2014 22:01
Location: ID

Terminal emulator issue

Postby nimdays » Sep 24, 2017 2:49

I read some tuts and then i tried this small one.
The problem is i must press enter after ctrl-z,c
Maybe you have a solution for this.

Code: Select all

#include "crt/unistd.bi"
#include "crt/sys/select.bi"
#inclib "util"

#define SIGINT 2
#define SIGQUIT 3
#define SIGTSTP 20

type sighandler as sub(byval as integer)

declare function forkpty alias"forkpty"(byval as integer ptr,byval as zstring ptr,_
        byval as any ptr,byval as any ptr)as integer

declare function signal alias"signal"(byval as integer,byval as sighandler)as sighandler

dim shared as integer m
static as pid_t pid

sub mysig(byval sig as integer)
   ?"signal " & sig & " caught"
   dim as byte c
   if sig = 2 then
     c = &h3
   elseif sig = 3 then
     c = &h1c
     c = &h1a
   end if
   write_(m, @c, 1)
end sub

pid = forkpty(@m,0,0,0)
if pid=0 then
end if

signal(SIGINT,@mysig) 'ctr-c
signal(SIGQUIT,@mysig) 'ctr-\
signal(SIGTSTP,@mysig) 'ctr-z

dim as fd_set fd_in
dim as integer rc
dim as zstring * 1024 buf

?"parent : " &getpid() & " child : " &pid

while (1)
   FD_SET_(m, @fd_in)
   rc = select_(m + 1, @fd_in,0,0, 0)
   if (FD_ISSET(0, @fd_in)) then
      rc = read_(0, @buf, sizeof(buf))
      write_(m, @buf, rc)
   elseif (FD_ISSET(m, @fd_in)) then
      rc = read_(m, @buf, sizeof(buf))
      write_(1, @buf, rc)
   end if

This is the output :

Code: Select all

tc@box:/tmp$ ./term1
parent : 6552 child : 6553
tc@box:/tmp$ cat
signal 20 caught
^Z[1]+  Stopped                    cat
tc@box:/tmp$ fg
signal 2 caught
tc@box:/tmp$ Terminated

killed from another window
Posts: 148
Joined: May 29, 2014 22:01
Location: ID

Re: Terminal emulator issue

Postby nimdays » Sep 27, 2017 23:19

I found a sample from qb64 forum.

Maybe can fix this.

Return to “Linux”

Who is online

Users browsing this forum: No registered users and 4 guests