Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

enumerate currently running applications in Linux

hi everybody,

can anybody tell me how to enumerate currently running applications in Linux programaticaly using C or Java.

please help me ...............

reply soon.

Comments

  • nugentnugent Member Posts: 87

    to get the number of processes running on a linux system you can parse the loadavg file in /proc. the format is as follows:

    load1 load2 load3 n_run/n_proc n_pid

    where load1, load2 and load3 are the load averages for the last 1, 5 and 15 minutes (these are the same values returned by uptime). the next field, n_run, is the number of kernel entities (processes/threads) currently running (this is always less than or equal to the number of cpu's in the machine, as only one process be executed at any per processor), n_proc is the total number of kernel entities on the machine, and n_pid is the process id of the most recently created process on the machine.

    to read this info open the file (/proc/loadavg) and read it into a buffer, then parse it with sscanf.

    you can use something like "%f %f %f %d/%d %lu" as the format field of sscanf.


    ------
    nugent



  • hiimsahiimsa Member Posts: 2
    [b][red]This message was edited by hiimsa at 2006-11-1 6:29:16[/red][/b][hr]
    [b][red]This message was edited by hiimsa at 2006-11-1 6:28:45[/red][/b][hr]
    :
    : to get the number of processes running on a linux system you can parse the loadavg file in /proc. the format is as follows:
    :
    : load1 load2 load3 n_run/n_proc n_pid
    :
    : where load1, load2 and load3 are the load averages for the last 1, 5 and 15 minutes (these are the same values returned by uptime). the next field, n_run, is the number of kernel entities (processes/threads) currently running (this is always less than or equal to the number of cpu's in the machine, as only one process be executed at any per processor), n_proc is the total number of kernel entities on the machine, and n_pid is the process id of the most recently created process on the machine.
    :
    : to read this info open the file (/proc/loadavg) and read it into a buffer, then parse it with sscanf.
    :
    : you can use something like "%f %f %f %d/%d %lu" as the format field of sscanf.
    :
    :
    : ------
    : nugent
    :
    :
    :
    :
    Thanks nuget,
    but i want the names of all currently running user applications in my program.

    please help me ...




  • nugentnugent Member Posts: 87
    If you look in /proc there will be many directories whose names are numbers, each one of these represents a process. In each of these directories you can find information about the process:

    cmdline: holds the complete command line for the process
    cwd: a symbolic link to the current working directory of the process
    environ: the environment of the process
    exe: a symbolic link containing the path of executed command
    fd: a directory containing 1 entry for each file the process has open
    maps: mapped memory regions and access permissions
    mem: used to access the page's of the process's memory
    root: symbolic link to the process's root directory
    smaps: memory consumption for each of the process's mappings (since 2.6.14)
    stat: status information (used by ps)
    statm: information about memory status in pages
    status: human readable format of stat and statm
    task: contains a directory for each thread in the process (since 2.6.0-test6)



    ------
    nugent



Sign In or Register to comment.