LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
Search this Thread
Old 11-01-2007, 11:22 AM   #1
sanjaykhuntia
LQ Newbie
 
Registered: Oct 2007
Posts: 14

Rep: Reputation: 0
netstat


hi,
can anyone plz tell me how to get the information what "netstat -nap" command gives? i want the pid, protocol, port number etc from this output. also i dont want to taking the help of parsing. is there any open code or api s available that does the same task as i want. please refer me any site which offers me that information.

my second question- how and from where can i get the process creation time of a process? i know that there are 3 times specifically atime,ctime,mtime maintained in stat structure for a file. but i need the create time of a process...

i hope i will get some good reply.


BTW thanks in advance.


sanjay
 
Old 11-01-2007, 01:02 PM   #2
vadiml
Member
 
Registered: Oct 2003
Posts: 42

Rep: Reputation: 19
Sanjay,

you can always read the netstat sources....
and for process creation time: look at the creation time of the /proc/$(PID) directory
 
Old 11-02-2007, 01:00 AM   #3
sanjaykhuntia
LQ Newbie
 
Registered: Oct 2007
Posts: 14

Original Poster
Rep: Reputation: 0
Re:

thanks for the suggestion,but one thing i doubt i have searched /proc directory thoroughly stll unable to get the process creation time. if you see the /proc/pid/stat, there you can fine 4 time stamps related to process but nothing is mentioned regarding the creation time. also you have to parse the stat file accordingly to get those times,, but not certain abt creation time. can you please give me a broad idea..

regards,
sanjay
 
Old 11-02-2007, 02:59 AM   #4
chrism01
Guru
 
Registered: Aug 2004
Location: Sydney
Distribution: Centos 6.6, Centos 5.10
Posts: 16,324

Rep: Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041Reputation: 2041
Well,
ps -ef
gives the process start time as 5th field
 
Old 11-02-2007, 06:38 AM   #5
vadiml
Member
 
Registered: Oct 2003
Posts: 42

Rep: Reputation: 19
Process creation time

Quote:
Originally Posted by sanjaykhuntia View Post
thanks for the suggestion,but one thing i doubt i have searched /proc directory thoroughly stll unable to get the process creation time. if you see the /proc/pid/stat, there you can fine 4 time stamps related to process but nothing is mentioned regarding the creation time. also you have to parse the stat file accordingly to get those times,, but not certain abt creation time. can you please give me a broad idea..

regards,
sanjay
I meant for a process id 5678 look at the creation time
of /proc/5678
 
Old 11-02-2007, 04:17 PM   #6
PAix
Member
 
Registered: Jul 2007
Location: United Kingdom, W Mids
Distribution: SUSE 11.0 as of Nov 2008
Posts: 195

Rep: Reputation: 40
Vadiml,
If you don't originally explain your requirement clearly, how can anyone work out you expect to see in the results?
From what I understand, you require to specify a process id (pid) in the call to the code?
Code:
ps -ef | awk -v pid="$1" '
$2==pid { if (substr($5, 3, 1) ==":")
              print "Pid " $2 " started at ", $5
          else
              print "Pid " $2 " was not started today"
        } '
If this is so and you decide to call the code "a1sh", then the call is
Code:
./a1sh 5676
and the output is one of these three:
Quote:
Pid 5678 was not started today

Pid 5678 started at 18:06
The first is when the process is found but started prior to the current date. No time, but the start date is given. The second is when the given pid isn't found and the third is when the pid is found and was started on the current date.

I hope that this meets your need? If not why not? Please explain carefully.

PAix
 
Old 11-02-2007, 10:52 PM   #7
ghostdog74
Senior Member
 
Registered: Aug 2006
Posts: 2,697
Blog Entries: 5

Rep: Reputation: 241Reputation: 241Reputation: 241
if you have lsof, an example only, prints out the start time at the end of each line.
Code:
ps -eo pid,start_time > processfile.txt
lsof -i -n > lsof.txt
awk 'FNR==NR{ a[$1]=$2;next}
    {
      print $0, $NF" "a[$2]  
    }        
' "processfile.txt" "lsof.txt"
 
  


Reply

Tags
creation, netstat, process, time


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
netstat Smooth Solaris / OpenSolaris 4 11-17-2006 01:30 AM
netstat -s r_213 Linux - Networking 2 01-27-2005 07:45 AM
route and netstat ray5_83 Programming 1 09-16-2004 02:12 PM
netstat -i r_213 Linux - Networking 4 09-09-2004 07:10 AM
netstat sopiaz57 Linux - Networking 1 10-14-2003 04:39 PM


All times are GMT -5. The time now is 07:58 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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration