enumerate processes


 
Thread Tools Search this Thread
Top Forums Programming enumerate processes
# 1  
Old 09-04-2008
PHP enumerate processes

Again for windows I can enumerate processes using toolhelp library

Code:
PROCESSENTRY32  pe32 = {0};
    HANDLE           hsp = CreateToolhelp32Snapshot( TH32CS_SNAPPROCESS, 0 );

    pe32.dwSize = sizeof( PROCESSENTRY32 );
    Process32First( hsp, &pe32 );
    do
    {
         // access   PROCESSENTRY32 values
        /*
        DWORD   dwSize;
        DWORD   cntUsage;
        DWORD   th32ProcessID;          // this process
        ULONG_PTR th32DefaultHeapID;
        DWORD   th32ModuleID;           // associated exe
        DWORD   cntThreads;
        DWORD   th32ParentProcessID;    // this process's parent process
        LONG    pcPriClassBase;         // Base priority of process's threads
        DWORD   dwFlags;
        CHAR    szExeFile[MAX_PATH];    // Path
        */

    } while( Process32Next( hsp, &pe32 ) );

Is there any way to do it in linux/unix,. Ineed process ID, parent process Id and process name. I tryes to scan /proc/ folder but I cannot figure out the subfolders and files.

Thank you
The red icon (on the top-left) is a hand or a question mark ? I thought is a Q mark
# 2  
Old 09-04-2008
try man pstat() - this works for some unixes
the /proc file system works for others - Linux is one.
# 3  
Old 09-09-2008
Something like this works with most unix'es and Linux that have /proc:

Code:
DIR *procfs;
struct dirent *entry;
procfs = opendir("/proc");
while ( entry = readdir(procfs) ) {
 if (!isdigit(entry->d_name[0])) continue;
 /* process id is in d_name. Open the file /proc/d_name/stat */
}

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Solaris

Enumerate disk instances in Solaris

HI, I need to find out what are all the hard disks connected in my System on Solaris? Also on my system when I ran the command prtconf, the following output is displayed. sd (driver not attached) st (driver not attached) sd, instance #0 (driver not attached) sd, instance... (1 Reply)
Discussion started by: rajujayanthy
1 Replies

2. Shell Programming and Scripting

Enumerate lines until each line break using awk

Hi, I have the following data: This this DT 0.99955 0 4 is be VBZ 1 5 7 sentence sentence NN 0.916667 8 16 one one NN 0.545078 17 20 . . Fp 1 20 21 This this DT 0.99955 22 26 is be VBZ 1 27 29 the the DT 1 30 33 second 2 JJ 0.930556 34 40 sentence sentence NN 0.916667 41 49... (1 Reply)
Discussion started by: owwow14
1 Replies

3. Shell Programming and Scripting

How to enumerate mounted disks and place output in array ?

Hi. I'm new to scripting / programming and was wondering what the best way to output all mounted storage devices and their names to an array would be ? I would like to achieve this using the bash shell. Any assistance with this would be greatly appreciated. Regards, Jonno :b: (4 Replies)
Discussion started by: Jonno888
4 Replies

4. Shell Programming and Scripting

Finding the age of a unix process, killing old processes, killing zombie processes

I had issues with processes locking up. This script checks for processes and kills them if they are older than a certain time. Its uses some functions you'll need to define or remove, like slog() which I use for logging, and is_running() which checks if this script is already running so you can... (0 Replies)
Discussion started by: sukerman
0 Replies

5. Shell Programming and Scripting

Enumerate ls -l output

Hi, I'm using normally ls -l to get the content of a directoy. But, it's possible to enumerate the ls output ? (like put the line number at the begining of each line) If it wasn't possible (I don't hope so ...), there's a way to get the line number the line had after doing a grep: ls -l... (8 Replies)
Discussion started by: tecnitek
8 Replies

6. UNIX for Advanced & Expert Users

How to enumerate USB Mass Storage devices?

Hi all, I want to write a program in C that can enumerate all USB massand their mount point storage on my system. i want to give ability to copy one file to desired USB mass storage or read a file from it. I have posted another question about how can recieve USB arrival in this forum. I think... (0 Replies)
Discussion started by: aghashahi
0 Replies

7. Solaris

Identifying and grouping OS processes and APP processes

Hi Is there an easy way to identify and group currently running processes into OS processes and APP processes. Not all applications are installed as packages. Any free tools or scripts to do this? Many thanks. (2 Replies)
Discussion started by: wilsonee
2 Replies

8. UNIX for Advanced & Expert Users

Monitoring Processes - Killing hung processes

Is there a way to monitor certain processes and if they hang too long to kill them, but certain scripts which are expected to take a long time to let them go? Thank you Richard (4 Replies)
Discussion started by: ukndoit
4 Replies

9. IP Networking

How to enumerate samba shares with client

I have a samba server node and I want to mount the samba (CIFS) shares from a second (client) unix machine. However, the unix mount command requires I specify the name of the share. What if I don't know the name of the share? How can I enumerate all the shares from the samba client machine? ... (1 Reply)
Discussion started by: siegfried
1 Replies

10. UNIX for Dummies Questions & Answers

processes

What command string will locate ONLY the PID of a process and ouput only the number of PID of the process? (1 Reply)
Discussion started by: mma_buc_98
1 Replies
Login or Register to Ask a Question