LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 06-13-2006, 07:37 AM   #1
levr
LQ Newbie
 
Registered: Jun 2006
Posts: 3

Rep: Reputation: 0
Finding the active terminal in linux


Hi,

I need to write a program that writes output to the active terminal of a specific user.

So if for example there are 10 users connected to the machine, and i need to write output to user number 2 and he has 4 terminals open - i need to write only to the active one.

How do i do that?


Thanks...
 
Old 06-13-2006, 07:59 AM   #2
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: NetBSD, Void, Debian, Mint, Ubuntu, Puppy, Raspbian
Posts: 3,487

Rep: Reputation: 224Reputation: 224Reputation: 224
???
if a terminal is open it is active
i've got 3 open at the moment so which one is active?
all of them.

look at talk that does it

Last edited by bigearsbilly; 06-13-2006 at 08:04 AM.
 
Old 06-13-2006, 08:08 AM   #3
levr
LQ Newbie
 
Registered: Jun 2006
Posts: 3

Original Poster
Rep: Reputation: 0
I ment by the active one - the one that was used last - the one to get the last input or command or the one that you are typing into at the moment etc.
 
Old 06-13-2006, 08:10 AM   #4
bigearsbilly
Senior Member
 
Registered: Mar 2004
Location: england
Distribution: NetBSD, Void, Debian, Mint, Ubuntu, Puppy, Raspbian
Posts: 3,487

Rep: Reputation: 224Reputation: 224Reputation: 224
yes sorry, i wasn't being helpful.
the talk prog does it correctly, maybe look at the source
or wait for a useful comment
 
Old 06-13-2006, 11:44 AM   #5
schneidz
LQ Guru
 
Registered: May 2005
Location: boston, usa
Distribution: fedora-30
Posts: 5,281

Rep: Reputation: 916Reputation: 916Reputation: 916Reputation: 916Reputation: 916Reputation: 916Reputation: 916Reputation: 916
i dont know how useful this is:

[untested]
you can cat to the actual device (e.g.- cat hello-world.txt > /dev/pts/0)
[/untested]

would it be that bad to send to all of them?
 
Old 06-13-2006, 08:23 PM   #6
levr
LQ Newbie
 
Registered: Jun 2006
Posts: 3

Original Poster
Rep: Reputation: 0
the program requirements are to print only to the active one.

Ive been told it can be done using the W command, to find the active one, and than to print to it as you said: cat hello-world.txt > /dev/pts/[active one].

But im not sure how.
 
Old 06-13-2006, 11:40 PM   #7
primo
Member
 
Registered: Jun 2005
Posts: 542

Rep: Reputation: 34
Try stat()'ing every terminal device file to find out who the owner is and the last time it was written to. The utmp file (read by w, who, et al - see utmp(5)) is supposed to contain information, but on X it happens that way with every xterm open, so the above approach may be better.
 
Old 06-13-2006, 11:58 PM   #8
theNbomr
LQ 5k Club
 
Registered: Aug 2005
Distribution: OpenSuse, Fedora, Redhat, Debian
Posts: 5,398
Blog Entries: 2

Rep: Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908Reputation: 908
If your linux is configured anything like securely, you will not be able to do that. If you could, what would stop malicious users from obliterating arbitrary user terminals?

--- rod.
 
Old 06-14-2006, 12:16 AM   #9
primo
Member
 
Registered: Jun 2005
Posts: 542

Rep: Reputation: 34
Quote:
Originally Posted by theNbomr
If your linux is configured anything like securely, you will not be able to do that. If you could, what would stop malicious users from obliterating arbitrary user terminals?

--- rod.
Right. It's the cause why commands like talk and wall are setuid/setgid to some user/group that has permissions on the device special files for terminals.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
active desktop from terminal giovannym Linux - Newbie 4 04-15-2005 12:33 AM
Finding files with terminal joeman3429 Fedora 10 07-22-2004 09:13 PM
Linux and active Directory jmirles Linux - Networking 0 06-19-2003 07:22 PM
finding programs in terminal? Boom Linux - Newbie 3 01-08-2003 02:09 AM
any active linux firewall tyler_durden Linux - Security 2 08-06-2001 12:09 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:36 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration