?
Solved

Terminals

Posted on 2004-04-09
4
Medium Priority
?
267 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
4 Comments
 
LVL 9

Accepted Solution

by:
Alf666 earned 100 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 100 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

Learn by Doing. Anytime. Anywhere.

Do you like to learn by doing?
Our labs and exercises give you the chance to do just that: Learn by performing actions on real environments.

Hands-on, scenario-based labs give you experience on real environments provided by us so you don't have to worry about breaking anything.

Question has a verified solution.

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

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 fix the unknown display problem in Linux Mint operating system. After installing the OS if you see Display monitor is not recognized then we can install "MESA" utilities to fix this problem or we can install additio…
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
Michael from AdRem Software explains how to view the most utilized and worst performing nodes in your network, by accessing the Top Charts view in NetCrunch network monitor (https://www.adremsoft.com/). Top Charts is a view in which you can set seve…
Suggested Courses

762 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