Solved

Terminals

Posted on 2004-04-09
4
232 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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…
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

758 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now