Solved

Terminals

Posted on 2004-04-09
4
251 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 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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying 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

Title # Comments Views Activity
Debian 3 - initrd rebuild 3 88
Problem to line 1 65
Alphanumeric pager notification on linux (may be script) when BMC Control-M job fails 6 111
what is this linux system is? 16 121
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…
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…

730 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