LinuxQuestions.org
Welcome to the most active Linux Forum on the web.
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 03-02-2017, 07:05 PM   #1
Linux_Kidd
Member
 
Registered: Jan 2006
Location: USA
Posts: 737

Rep: Reputation: 78
find UID terminal name/PID/PPID


what the easiest way to find the PPID's of terminal PID's for active line users?

i am able to awk a who -a for the lines that are "+" to get the active line PID's, from there i can ps -o ppid to find the PPID, and finally find that parent in ps.

but is there a easier way?

Last edited by Linux_Kidd; 03-03-2017 at 04:07 PM. Reason: spelling
 
Old 03-02-2017, 07:17 PM   #2
r3sistance
Senior Member
 
Registered: Mar 2004
Location: UK
Distribution: CentOS 6/7
Posts: 1,375

Rep: Reputation: 217Reputation: 217Reputation: 217
I don't think you have phrased this question right, it sounds like you are after the PID and PPID of the current terminal, this may change by shell but in BASH the following should work.

Code:
# echo "PID: "$$", PPID: "$PPID
PID: 32538, PPID: 32537
and to confirm

Code:
# ps -o ppid,pid,cmd
 PPID   PID CMD
32538   318 ps -o ppid,pid,cmd
32537 32538 -bash

Last edited by r3sistance; 03-02-2017 at 07:18 PM.
 
1 members found this post helpful.
Old 03-03-2017, 04:06 PM   #3
Linux_Kidd
Member
 
Registered: Jan 2006
Location: USA
Posts: 737

Original Poster
Rep: Reputation: 78
i want the process name that started the line PID of all active lines, etc.
in other words, the PPID name of active line PID

as example, my ssh session is pts/0
the line has PID 1220, and a PPID 1216, ps 1216 is a SSHD fork "sshd: root@pts/0"
1216 PPID is /usr/sbin/sshd, and its PPID is 1 (init)

but, i yank active lines with
Code:
who -a | awk '$2 == "+" {print $7;}'
i am looking for a more elegant way, etc.
 
Old 03-20-2017, 03:04 PM   #4
Linux_Kidd
Member
 
Registered: Jan 2006
Location: USA
Posts: 737

Original Poster
Rep: Reputation: 78
bump, just seeking one last time.
anyone have a better way?
 
Old 03-20-2017, 03:21 PM   #5
rtmistler
Moderator
 
Registered: Mar 2011
Location: USA
Distribution: MINT Debian, Angstrom, SUSE, Ubuntu, Debian
Posts: 9,915
Blog Entries: 13

Rep: Reputation: 4948Reputation: 4948Reputation: 4948Reputation: 4948Reputation: 4948Reputation: 4948Reputation: 4948Reputation: 4948Reputation: 4948Reputation: 4948Reputation: 4948
There's a better suggestion using scripting in the answer provided by user hadarot on 8/29/2005 in the following link:

http://www.unix.com/shell-programmin...-pid-only.html

Honestly for me, I'm a C programmer and thus I use getpid() and getppid(), http://man7.org/linux/man-pages/man2/getpid.2.html

Note also that in the /proc subsystem for any given process, this information exists within the file structure.
 
  


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 find out the highest UID number? jithinjjc Linux - Newbie 7 02-12-2014 01:01 AM
[SOLVED] cannot find username for UID 500 linuxdistroyer Linux - General 3 04-07-2011 04:06 AM
uid and gid fileds from /proc/pid/status sanjaykhuntia Linux - Enterprise 2 02-11-2011 02:35 PM
strange pid and ppid problem asvija Linux - General 1 03-10-2005 02:53 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 03:20 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