Main Page | Report this Page
 
Linux Forum Index  »  Linux Development - System  »  how to figure out theterminal the process is running...
Page 1 of 1    

how to figure out theterminal the process is running...

Author Message
zix...
Posted: Fri Oct 09, 2009 4:23 am
Guest
Hi,
I have a program. Now, I have to figure out whether its been run
through serial console or through ssh, specifically serial? Is there
any API that I can use in linux?

how to get the env variable $TERM? hopefully, this can also solve the
issue.


Regards,
zix
 
rounak...
Posted: Fri Oct 09, 2009 7:13 am
Guest
On Oct 9, 7:23 pm, zix <zixe... at (no spam) gmail.com> wrote:
Quote:
Hi,
   I have a program. Now, I have to figure out whether its been run
through serial console or through ssh, specifically serial? Is there
any API that I can use in linux?

how to get the env variable $TERM? hopefully, this can also solve the
issue.

Regards,
zix

You can use getenv() to get the value of an environmental variable.
But I think it will not help in this case.

-Rounak.
 
Rainer Weikusat...
Posted: Fri Oct 09, 2009 11:54 am
Guest
rounak <rounakhawking at (no spam) gmail.com> writes:
Quote:
On Oct 9, 7:23 pm, zix <zixe... at (no spam) gmail.com> wrote:
   I have a program. Now, I have to figure out whether its been run
through serial console or through ssh, specifically serial? Is there
any API that I can use in linux?

how to get the env variable $TERM? hopefully, this can also solve the
issue.

Regards,
zix

You can use getenv() to get the value of an environmental variable.
But I think it will not help in this case.

It certainly won't. The value of TERM is supposed to be some string
which the ncurses-library can use to determine how to support a
particular type of terminal.
 
zix...
Posted: Fri Oct 09, 2009 8:40 pm
Guest
Quote:
What do you mean by "run through [a] serial console or through ssh"?
You /can/ programmatically determine the characteristics of the controlling
terminal and/or any character-special device that a process uses, but how
you go about that depends on what you are looking for, and why you are
looking for it. For instance, in order to avoid a termination signal when
an SSH session closes, you want to look at the controlling terminal (which
may not be one of the open files in the process). OTOH, if you want to
ensure that any terminal interaction is performed through a direct-attached
device, you want to look at the process' open files.

So, do you mean "initiated from a shell command entered through a serial
console"? Or do you mean "having attached to a serial console through stdin,
stdout, stderr"? Or do you mean "having attached to a serial console
through an explicit open()"?


Hi,
i am reiterating my ques: I have changed my shell to my customised
shell in /etc/inittab. Now I want to know if I entering the shell
through serial/ssh? I have tried ctermid, but both returns "/dev/tty".
i want something to point to /dev/ttyS0. Are there any API's for this?
Thanks a lot

zix
 
Lew Pitcher...
Posted: Sat Oct 10, 2009 5:14 am
Guest
On Oct 10, 2:40 am, zix <zixe... at (no spam) gmail.com> wrote:
Quote:
What do you mean by "run through [a] serial console or through ssh"?
You /can/ programmatically determine the characteristics of the controlling
terminal and/or any character-special device that a process uses, but how
you go about that depends on what you are looking for, and why you are
looking for it. For instance, in order to avoid a termination signal when
an SSH session closes, you want to look at the controlling terminal (which
may not be one of the open files in the process). OTOH, if you want to
ensure that any terminal interaction is performed through a direct-attached
device, you want to look at the process' open files.

So, do you mean "initiated from a shell command entered through a serial
console"? Or do you mean "having attached to a serial console through stdin,
stdout, stderr"? Or do you mean "having attached to a serial console
through an explicit open()"?

Hi,
    i am reiterating my ques: I have changed my shell to my customised
shell in /etc/inittab. Now I want to know if I entering the shell
through serial/ssh? I have tried ctermid, but both returns "/dev/tty".
i want something to point to /dev/ttyS0. Are there any API's for this?
Thanks a lot

If you are using /etc/inittab to start your customized shell, then
you /already/ know which invocations come from a direct-attached
device and which do not; that's one of the byproducts of using
inittab. So, just pass that information along in a parameter to your
script, as part of the inittab entry's commandline.

I.e.
# direct-attached serial console
c1:1235:respawn:/my/special/script -localdevice=TRUE </dev/ttyS0 >/
dev/ttyS0

# some other device
x1:1235:respawn:/my/special/script -localdevice=FALSE </dev/pts/1 >/
dev/pts/1
 
 
Page 1 of 1    
All times are GMT - 5 Hours
The time now is Sun Nov 22, 2009 6:15 am