The UNIX and Linux Forums  

Go Back   The UNIX and Linux Forums > Top Forums > High Level Programming
Google UNIX.COM


High Level Programming Post questions about C, C++, Java, SQL, and other programming languages here.

More UNIX and Linux Forum Topics You Might Find Helpful
Thread Thread Starter Forum Replies Last Post
get program name give a process id naren_chella HP-UX 1 09-01-2006 04:33 AM
possible to run script to enter info within a program? lianderthal Shell Programming and Scripting 1 06-09-2005 03:40 PM
Linux process info nayeemmz Linux 2 02-09-2005 03:43 PM
IO by Process/program cpiuk HP-UX 2 09-16-2004 01:24 AM
How can I get the file info of my process?ugent!!!!! nsun High Level Programming 2 07-02-2003 06:02 PM

Reply
 
Submit Tools LinkBack Thread Tools Search this Thread Display Modes
  #1  
Old 02-14-2008
Registered User
 

Join Date: Sep 2007
Location: Huntsville, Alabama
Posts: 6
Getting process info in a program

Hi,
I am wondering if there is a way to find out in a C software program if a particular process is running without having to write a file. In the past, I have been using the system command to execute a pgrep and output the info to a file. Then the C program reads the file to make the determination, and the file is deleted.

I have a request from my customer to find out this same info in the C program without writing a file. HP-UX has a pstat_getproc utility that would work, but this is not supported in most Unix variants. Is there some other way for a software program to detect if another process is running?

Thanks,
Herb Miller
Reply With Quote
Forum Sponsor
  #2  
Old 02-14-2008
Registered User
 

Join Date: Nov 2005
Posts: 25
Depends on the platforms you're supporting

Most flavors of UNIX support process accounting on some level, but each of them implement it a little differently. Both AIX and Solaris have process structs available in the /usr/include/sys/proc.h files. You may have to do a bit of digging to find a method to give you back exactly what you want, but that's a place to start.

The only exception to this is Linux, which doesn't have the process accounting libraries that most of the other UNIXs have. Process accounting in Linux is done through the /proc filesystem, which are nominally a set of files updated with the necessary process info in real time. If you're looking to accomplish this on Linux, you'll need to do some digging to find out what's relevant. Of course, if you're just looking for basic info, you can have your program run the 'ps' command and parse the output.

Hope that helps.
Reply With Quote
Google The UNIX and Linux Forums
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes




All times are GMT -7. The time now is 06:24 PM.


Powered by: vBulletin, Copyright ©2000 - 2006, Jelsoft Enterprises Limited.
The UNIX and Linux Forums Content Copyright ©1993-2008. All Rights Reserved.Ad Management by RedTyger Visit The Complex Event Processing Blog

Content Relevant URLs by vBSEO 3.2.0