Solved

Terminals

Posted on 2004-04-09
4
247 Views
Last Modified: 2010-04-22
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
Comment
Question by:karana
4 Comments
 
LVL 9

Accepted Solution

by:
Alf666 earned 25 total points
ID: 10793372
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
 
LVL 1

Assisted Solution

by:ravenscr98
ravenscr98 earned 25 total points
ID: 10795637
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

829 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question