LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Home Forums Tutorials Articles Register
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 03-31-2009, 02:31 AM   #1
rheosiva
LQ Newbie
 
Registered: Jan 2008
Location: india
Distribution: Fedora
Posts: 17

Rep: Reputation: 0
How to get the Process State using PID


Is there any Specific System library calls to do that in Linux..
Please tell if any API is available..
 
Old 03-31-2009, 02:46 AM   #2
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
Just translate the shell command below to C (or whatever).
Code:
grep ^State /proc/<pid>/status
 
Old 03-31-2009, 03:04 AM   #3
rheosiva
LQ Newbie
 
Registered: Jan 2008
Location: india
Distribution: Fedora
Posts: 17

Original Poster
Rep: Reputation: 0
thanks...
But still i am searching for any API which can do this..
 
Old 03-31-2009, 07:43 AM   #4
wje_lq
Member
 
Registered: Sep 2007
Location: Mariposa
Distribution: FreeBSD,Debian wheezy
Posts: 811

Rep: Reputation: 179Reputation: 179
Use these:
Code:
sprintf()      /* to form /proc/desired_pid/status */
open()         /* the file whose name you just formed */
read()         /* to get the data */
close()        /* to close the file */
... then whatever normal C manipulations you want to focus in on the data you want within the data you've just read.

It's as simple and straightforward an API as you could want.
 
Old 04-01-2009, 03:05 AM   #5
rheosiva
LQ Newbie
 
Registered: Jan 2008
Location: india
Distribution: Fedora
Posts: 17

Original Poster
Rep: Reputation: 0
thanks .... It really helps
 
  


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
Getting pid of a process!! vishamr2000 Programming 34 03-12-2015 07:12 AM
how to get the name of process from PID in C/C++? kulandaivelu Programming 3 02-03-2009 09:41 AM
How to get the PID of the process giving kill signal to a process? hariprd Programming 2 11-27-2008 03:10 AM
pid of a process kushkothari Programming 8 11-19-2008 05:06 AM
[C++] Get process ID (PID) Moraxus Programming 5 10-16-2008 12:31 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

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