LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Networking
User Name
Password
Linux - Networking This forum is for any issue related to networks or networking.
Routing, network cards, OSI, etc. Anything is fair game.

Notices


Reply
  Search this Thread
Old 12-05-2006, 06:53 PM   #1
Termina
LQ Newbie
 
Registered: Mar 2004
Distribution: Debian
Posts: 14

Rep: Reputation: 0
How can I find my sshd pid on connect?


I would like to make a script that grabs the pid of the sshd I spawn when I connect to a machine.

Does anyone know a good way to do this that wouldn't generate false positives?

Thanks!
 
Old 12-05-2006, 07:17 PM   #2
Termina
LQ Newbie
 
Registered: Mar 2004
Distribution: Debian
Posts: 14

Original Poster
Rep: Reputation: 0
Sorry, seem to have found a way to do it. If anyone else every wants to do this, here's the command I use to (later) kill my sshd (even if there's a tunnel, nothing can stop this! muwhahahaa!)

kill -9 $(cat /proc/`echo $$`/stat | cut -d " " -f 4)
 
Old 12-05-2006, 07:30 PM   #3
unSpawn
Moderator
 
Registered: May 2001
Posts: 29,415
Blog Entries: 55

Rep: Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600Reputation: 3600
In Bash this "cat /proc/`echo $$`/stat | cut -d " " -f 4" is bloat for "echo $$" :-]
Besides, it's not the PID of your sshd but your current shell. If you "ps f" it you would see:
Code:
 
sshd root (master sshd)
  \
  sshd root (privsep)
     \
     sshd $LOGNAME (pts)
        \
        shell ($$)
so the most you can get is "pgrep -U $LOGNAME -f sshd".
 
  


Reply



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 the PID of a process using C programming? socialjazz Programming 3 10-06-2006 12:53 AM
Find out heap size for a PID luexiong Linux - General 1 03-29-2005 09:40 AM
how to find all files with pid Zac2003 Linux - Software 2 10-27-2004 09:44 PM
sshd at startup and pid questions :) breakerfall Linux - General 4 09-28-2003 08:14 PM
How to find the pid to stop a process.... vous Linux - Networking 6 08-14-2003 04:18 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Networking

All times are GMT -5. The time now is 11:08 PM.

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