ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I'm not sure, if that is the proper way to phrase, what I am asking, anyway...
I am making a program which allows me to moniter users using my box, (knock 'em off sshd/view what they're doing, etc) but I can't figure out how to kill the proper terminal, I can get the login pid using utmp, but I need the tty/pty/pts id.. Any ideas on how to do this?
the numbers are all process id's and are folders. in a process id folder it looks like this:
Quote:
<o7:> cd 985
<o7:> ls
cmdline cwd environ exe fd maps mem mounts root stat statm status
<o7:> cat stat
985 (xmms) S 1 984 984 0 -1 0 589 0 1501 0 5484 925 0 0 15 0 0 0 18942 50507776 2066 4294967295 134512640 135467008 3221224240 3221223788 1108157003 0 0 4102 1024 3222420269 0 0 17 0
however using /proc/, to quote stevens, is an ugly hodgepodge. iirc the way to do this stuff is thru sysctl calls. i've used sysctl for routing and network stuff, but not for process stuff yet. however it would be a fun project and im going to try now i think thanks for the inspiration! for now tho you can just parse the data in /proc/your_pid/stat file.
ps. if you're interested in doing the sysctl way, have a look at file: /usr/include/linux/sysctl.h it shows you the request structure kinda. you'll need to read the man pages and prolly google for a sysctl() tutorial. i may have some old code lying around if you want to check it out?
Last edited by infamous41md; 11-25-2003 at 03:20 PM.
damn there seems to be not much info at all on how to use sysctl. this seems to be another one of those things to just hack ur way thru. all of the standard linux utilities DONT use sysctl, they all cheat and use /proc. does anyone else have any source for utilities that use sysctl? here is teh little piece of code i wrote awhile ago, it shows the general idea. if you read the above mentioned header file you'll see how it works. the requests form a hierarchical structure.
man sysctl says: sysctl is used to modify kernel parameters at runtime. The parameters available are those listed under /proc/sys/
If it only does the /proc/sys things, it cannot be used for the pid things. IMHO it's not "ugly" to use /proc directly from a program. It is the way to do it AFAIK.
Originally posted by zer0python [...] but I can't figure out how to kill the proper terminal, I can get the login pid using utmp, but I need the tty/pty/pts id.. Any ideas on how to do this?
Getting the terminal name (/dev/pts/2) is as easy as getting the login PID:
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.