LinuxQuestions.org
Review your favorite Linux distribution.
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 05-23-2009, 09:55 AM   #1
dinob
LQ Newbie
 
Registered: Dec 2008
Posts: 2

Rep: Reputation: 0
HOW TO get TTY id from a c programm


Hi experts,

I am new to linux/c programming and I am trying to get TTY id from my c program. Something like this:

int TTYID = get_ttyid();

How do I do that?

Regards,
_dino_
 
Old 05-23-2009, 02:10 PM   #2
harry edwards
Member
 
Registered: Nov 2007
Location: Lincolnshire, UK
Distribution: CentOS, Fedora, and Suse
Posts: 365

Rep: Reputation: 48
See man ttyname. Sample follows:

Code:
#include <stdio.h>
#include <sys/types.h>


static const char tty_usage[] = "tty\n"
#ifndef BB_FEATURE_TRIVIAL_HELP
	"\nPrint the file name of the terminal connected to standard input.\n\n"
	"Options:\n"
	"\t-s\tprint nothing, only return an exit status\n"
#endif
	;

extern int tty_main(int argc, char **argv)
{
	char *tty;

	if (argc > 1) {
		if (argv[1][0] != '-' || argv[1][1] != 's')
			usage(tty_usage);
	} else {
		tty = ttyname(0);
		if (tty)
			puts(tty);
		else
			puts("not a tty");
	}
	return(isatty(0) ? TRUE : FALSE);
}
 
  


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
How to reset/restart a tty from another tty? armandino Linux - General 4 02-25-2009 03:09 AM
can a tty execute command on another tty? BeacoN Linux - Desktop 3 11-08-2008 09:39 AM
How window in programm can be resized by another programm. rexStart Programming 1 09-23-2008 02:47 AM
I it possible to kill a tty or find which tty is being using by which process? geletine Linux - Software 2 01-15-2006 08:40 AM
change tty => system crashes (ati driver/tty resolution) mosca Debian 6 08-05-2004 07:37 AM

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

All times are GMT -5. The time now is 03:39 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
Open Source Consulting | Domain Registration