how to find the current tty?

Ask a Question related to UNIX Programming, Design and Development.

  1. #1

    Default how to find the current tty?

    Hello,
    I'm trying to find out how I can tell the current tty from a daemon
    written in C. ttyname() is useful only for the tty I start it on, but
    how should I do it after that? Besides, ttyname() doesn't help if I
    close fds 0, 1 and 2. I'm running Linux.
    Any ideas?

    Thanks,

    andrej

    --
    echo ${girl_name} > /etc/dumpdates
    Andrej Hocevar Guest

  2. Similar Questions and Discussions

    1. Using DW find to find tags not on page
      I transfering content from 1498 static pages into a MySQL database. I've isolated 1450 pages with single h1 or h2 tags that I can use in the title...
    2. Either BOF or EOF is True, or the current record hasbeen deleted. Requested operation requires a current record
      Can anyone pls help? I am getting the following error when search my database. "ADODB.Field (0x800A0BCD Either BOF or EOF is True, or the...
    3. trailing slash issue in Find.find
      require "find" Find.find("/usr/bin/") { |file| puts file } /usr/bin//rmdir /usr/bin//rm /usr/bin//mv /usr/bin//mknod /usr/bin//mkfifo...
    4. highlight current row?
      developer 6 win and mac In list view I want to highlight the current row with a color. I know it is done with a container field and a graphic color...
    5. How to change the current thread current culture at run time.
      I have created a new culture : Dim objCulture As New CultureInfo("he") //hebrew When I tried to assign it to the current thread. ...
  3. #2

    Default Re: how to find the current tty?

    In article <slrnbj2geq.1m3.drejcica@sonet.utopija.linux>,
    Andrej Hocevar <drejcica@volja.net> wrote:
    >Hello,
    >I'm trying to find out how I can tell the current tty from a daemon
    >written in C. ttyname() is useful only for the tty I start it on, but
    >how should I do it after that? Besides, ttyname() doesn't help if I
    >close fds 0, 1 and 2. I'm running Linux.
    A daemon doesn't usually have a current tty, so what are you expecting to
    get?

    --
    Barry Margolin, [email]barry.margolin@level3.com[/email]
    Level(3), Woburn, MA
    *** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
    Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.
    Barry Margolin Guest

  4. #3

    Default Re: how to find the current tty?

    On Wed, 06 Aug 2003 17:53:27 GMT, Andrej Hocevar <drejcica@volja.net>
    wrote:
    > Hello,
    > I'm trying to find out how I can tell the current tty from a daemon
    > written in C. ttyname() is useful only for the tty I start it on, but
    > how should I do it after that? Besides, ttyname() doesn't help if I
    > close fds 0, 1 and 2. I'm running Linux.
    > Any ideas?
    >
    > Thanks,
    >
    > andrej
    >

    A bit more precison is needed... the system maintains a "control terminal"
    for each process (possibly non-existent) that you can retrieve with
    ctermid, but that's likely to just return the string "/dev/tty" -- perhaps
    that is OK.

    Or if you mean something else by "current tty," could you explain a bit
    more?

    --Marc
    Marc Rochkind Guest

  5. #4

    Default Re: how to find the current tty?

    On Wed, 6 Aug 2003, Andrej Hocevar wrote:
    > I'm trying to find out how I can tell the current tty from a daemon
    > written in C. ttyname() is useful only for the tty I start it on, but
    > how should I do it after that? Besides, ttyname() doesn't help if I
    > close fds 0, 1 and 2. I'm running Linux.
    Umm, daemons don't have a "current tty". WHat are you trying
    to achieve?

    --
    Rich Teer, SCNA, SCSA

    President,
    Rite Online Inc.

    Voice: +1 (250) 979-1638
    URL: [url]http://www.rite-online.net[/url]

    Rich Teer Guest

  6. #5

    Default Re: how to find the current tty?

    In article <9ubYa.65$Mg5.1@news.level3.com>, Barry Margolin wrote:
    > A daemon doesn't usually have a current tty, so what are you expecting to
    > get?
    Right. Either my question was not precise enough or my concept was
    somehow wrong. Here's what I'm trying to do. I have my daemon
    lurking in the background (forked twice), waiting for the user to
    take some specified action (move the mouse wheel). When it happens,
    it is supposed to send an event to the _user's_ current console with
    an ioctl call. Unfortunatelly, it only works for the console I start
    it on; however, eventually, init might start it in the future so
    even that won't work anymore. So I need a way to get the name of the
    tty the user is currently using.

    After some thinking, this became unclear even to myself.

    But I took a look at the kernel sources (2.4.20) and found this in
    the drivers/char/console.c file:

    /*
    * fg_console is the current virtual console,
    * last_console is the last used one,
    * want_console is the console we want to switch to,
    * kmsg_redirect is the console for kernel messages,
    */
    int fg_console;
    int last_console;
    int want_console = -1;
    int kmsg_redirect;

    Clearly, something like that is used when alt-left_arrow is pressed
    to switch to the next tty.
    I'm sure now that there must be a way of getting the information I
    need, but probably with another approach.

    Has anyone got any ideas?

    Thanks,

    andrej

    --
    echo ${girl_name} > /etc/dumpdates
    Andrej Hocevar Guest

  7. #6

    Default Re: how to find the current tty?

    In article <_%tYa.4$7R.3@news.level3.com>, Barry Margolin wrote:
    > This doesn't make sense. If the user has 5 xterm windows open, he's using
    > 5 tty's.
    It does make sense -- only not in X, which I don't want, anyway.


    --
    echo ${girl_name} > /etc/dumpdates
    Andrej Hocevar Guest

  8. #7

    Default Re: how to find the current tty?

    On Thu, 07 Aug 2003 09:38:08 GMT, Andrej Hocevar <drejcica@volja.net>
    wrote:
    > In article <9ubYa.65$Mg5.1@news.level3.com>, Barry Margolin wrote:
    >> A daemon doesn't usually have a current tty, so what are you expecting
    >> to
    >> get?
    >
    > Right. Either my question was not precise enough or my concept was
    > somehow wrong. Here's what I'm trying to do. I have my daemon
    > lurking in the background (forked twice), waiting for the user to
    > take some specified action (move the mouse wheel). When it happens,
    > it is supposed to send an event to the _user's_ current console with
    > an ioctl call. Unfortunatelly, it only works for the console I start
    > it on; however, eventually, init might start it in the future so
    > even that won't work anymore. So I need a way to get the name of the
    > tty the user is currently using.
    >
    [snip]

    There are some records kept, which are used by the who command.

    Look at the documentation for getutxent and the header utmpx.h. Maybe this
    is what you're looking for. But, as I think Barry pointed out, these
    records don't necessarily tell you exactly what tty the user is using, only
    how he or she logged in.

    --Marc
    Marc Rochkind Guest

  9. #8

    Default Re: how to find the current tty?

    In article <slrnbj50ai.hh.drejcica@sonet.utopija.linux>,
    Andrej Hocevar <drejcica@volja.net> wrote:
    >In article <_%tYa.4$7R.3@news.level3.com>, Barry Margolin wrote:
    >> This doesn't make sense. If the user has 5 xterm windows open, he's using
    >> 5 tty's.
    >
    >It does make sense -- only not in X, which I don't want, anyway.
    If he's not running a window system, but he's using the system console,
    then /dev/console is probably the device you want.

    --
    Barry Margolin, [email]barry.margolin@level3.com[/email]
    Level(3), Woburn, MA
    *** DON'T SEND TECHNICAL QUESTIONS DIRECTLY TO ME, post them to newsgroups.
    Please DON'T copy followups to me -- I'll assume it wasn't posted to the group.
    Barry Margolin Guest

  10. #9

    Default Re: how to find the current tty?

    Barry Margolin <barry.margolin@level3.com> wrote:
    >In article <slrnbj50ai.hh.drejcica@sonet.utopija.linux>,
    >Andrej Hocevar <drejcica@volja.net> wrote:
    >>In article <_%tYa.4$7R.3@news.level3.com>, Barry Margolin wrote:
    >>> This doesn't make sense. If the user has 5 xterm windows open, he's using
    >>> 5 tty's.
    >>
    >>It does make sense -- only not in X, which I don't want, anyway.
    >
    >If he's not running a window system, but he's using the system console,
    >then /dev/console is probably the device you want.
    This question was multiposted to several groups, and hence has
    split the discussion in a very unproductive way.

    He is using Linux, has multiple virtual consoles, and apparently
    wants the functionality of gpm, where he is intercepting the
    mouse (or in his case possibly the keyboard too) and needs to
    know which vc is actually being displayed on the system monitor.

    Despite the fuzzy responses, it appears that in some newsgroups
    others have narrowed it down to what he does want and are
    attempting to explain where he can find examples.

    Perhaps the best thing in this newsgroup would be to just drop
    the thread and ignore it.

    --
    Floyd L. Davidson <http://web.newsguy.com/floyd_davidson>
    Ukpeagvik (Barrow, Alaska) [email]floyd@barrow.com[/email]
    Floyd Davidson Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139