[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 277
  • Last Modified:

Terminals

sir ,

           i   m working on p3 machine in RedHat 8 os .

 i  opened two terminals tty1 & tty2 using root
password .

******************  1.c   **************
      int main()
                 {
                       int  f;
                       f=open("/dev/tty2" ,O_WRONLY);
                       write(f ,"clear\n" ,6);
                     }

i comiled 1.c  from tty1   and  run on tty1 .
    i   got printed like the below .  

    > clear
     
my intention is to run the clear system call on
terminal tty2 .

how can i do this ?



       
0
karana
Asked:
karana
2 Solutions
 
Alf666Commented:
clear is no system call. It's a program. It uses the termcap or terminfo database to determine the correct sequence of escape codes to send to your terminal.

On all ansi screens, you should be able to clear the screen using the following sequence :

\E[H\E[J (where \E is the escape code).

So, theoritically (I did not test it), the following might work :

      int main()
                 {
                       int  f;
                        char clear[6] ;
                        clear[0] = 0x1b ;
                        clear[1] = '[' ;
                        clear[2] = 'H' ;
                        clear[3] = 0x1b ;
                        clear[4] = '[' ;
                        clear[5] = 'J' ;

                       f=open("/dev/tty2" ,O_WRONLY);
                       write(f , clear, 6);
                     }

Bu the best method would be to use the termcap/terminfo databases to find out the proper sequence.
0
 
ravenscr98Commented:
Is your intention to have a process running on tty1 be able to clear terminal tty2 using file i/o or a system call?  Or do you want to have the process running on tty1 actually execute the clear command or execute other unix commands on tty2?   For the former, do as Alf666 suggested and write out the clear screen escape sequence to tty2.  For the latter you need to have a process running that has tty2 as its standard i/o so that it can use the "exec" command to execute system commands.

To accomplish this do something like this.

Start a process on tty1.
Have it fork a child process with a pipe connecting the two processes.
Have the child process close its standard i/o file descriptors (0,1,2).
Have the child process open tty2 on its standard i/o file descriptors.
Have the child process read commands from the parent process via the pipe, and exec them.  Since exec will inherit the file descriptors of it's calling process, commands will execute on tty2.
0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now