Getting process info in a program


 
Thread Tools Search this Thread
Top Forums Programming Getting process info in a program
# 1  
Old 02-14-2008
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
# 2  
Old 02-14-2008
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.
Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

How can I get parent process program name?

Hi: I have 2 script on AIX server. The child script is called by parent script. For example: The parent script full name is /home/op/def/parent.spt, which calls /home/op/abc/child.spt I want to get the parent program name with full path name (i.e. /home/op/def/parent.spt), in... (3 Replies)
Discussion started by: cstsang
3 Replies

2. UNIX for Dummies Questions & Answers

kill/pkill process by CMD info.

I have a process that I'd like to kill. Doing a "ps -fu myusername" gives me: UID PID PPID C STIME TTY TIME CMD myusername 5443 1 0 10:05 ? 00:00:00 /bin/sh /some/path/crap.sh -s /yet/another/path/parentProcess myusername 5593 5443 0 ... (2 Replies)
Discussion started by: mrwatkin
2 Replies

3. AIX

How to access process and cpu info on AIX?

Hi, may be this is an AIX noob question: my current C++ application runs on Linux and is quite memory consuming. Therefore, the application writes a logfile after it has finished containing memory information, CPU information, information on the running other processes besides my application... (5 Replies)
Discussion started by: DarthVader77
5 Replies

4. Programming

program or script to display user info

I'm on a Linux machine and need a program that will display user information as follows: user name, user directory and current date & time. I think we can compile C, C++ and Perl. All help is appreciated. (4 Replies)
Discussion started by: flasun
4 Replies

5. Programming

process info

Can any one tell me how does 'ps' command get information about the processes from operating system data structures? (4 Replies)
Discussion started by: clintoo
4 Replies

6. HP-UX

get program name give a process id

Hi , I have query regarding to get a program name given a pid in HP-Ux . give procees id ( PID) i would like to retrieve the process/program through a C program ? my input to c program will be will be pid and i would like to know what is process name /program name . Many Thanks ... (1 Reply)
Discussion started by: naren_chella
1 Replies

7. Shell Programming and Scripting

possible to run script to enter info within a program?

hi, I am new to Unix and script writing so I was wondering if this would be possible and how I might do it. I've learned to write a basic script and the first step I need to do is to open a program (for genetic linkage). The program then requires me to enter a lot of information. Sort of line... (1 Reply)
Discussion started by: lianderthal
1 Replies

8. Linux

Linux process info

Hello, I had a back job scheduled to run at 2 am in the morning in my crontab. I found out that the job did not initiate and there were no logs dumped as to the reason for the failure to initiate. I found the process had started but failed to trigger the job and it had actually hung because it... (2 Replies)
Discussion started by: nayeemmz
2 Replies

9. HP-UX

IO by Process/program

HI there, I'm trying to find a way of showing the IO's performed by individual programs. Number of reads/writes IO time that kind of thing. Anybody know of any way to show this information. Free little downloads that kind of thing? Cheers Phil (2 Replies)
Discussion started by: cpiuk
2 Replies

10. Programming

How can I get the file info of my process?ugent!!!!!

my project is very big,has many module and sub procedure that written by others,so how to get info of thel file opened or unclosed in my project ? I think there are two ways: 1. with pid_t get process info ,and via file table ( /usr/include/sys/file.h) to check file info. 2. in very... (2 Replies)
Discussion started by: nsun
2 Replies
Login or Register to Ask a Question