How to get the process id starting from the application name (in C)

How to get the process id starting from the application name (in C)

Post by Giuseppe Grec » Sat, 24 Jun 2000 04:00:00



Hi to everybody.

I wrote a SNMP agent that allows users to remotely start and stop
applications. This agent must be portable on Windows NT and HP-UX. I
completed the Windows NT implementation without problems. The HP-UX
implementation if 90% OK. I have one small problem only. When a user want to
remotely stop an application (the user just specify the application name),
my SNMP agent needs the process id in order to call the kill() function.
Could you tell me how can I get the process id starting from the application
name (of course, in a C program)?

Thanks.

Giuseppe Greco

 
 
 

How to get the process id starting from the application name (in C)

Post by Alexander Soliani » Sat, 24 Jun 2000 04:00:00


What will you do if there are two processes with
the same names but different PIDs?

--


Quote:> Hi to everybody.

> I wrote a SNMP agent that allows users to remotely start and stop
> applications. This agent must be portable on Windows NT and HP-UX. I
> completed the Windows NT implementation without problems. The HP-UX
> implementation if 90% OK. I have one small problem only. When a user want
to
> remotely stop an application (the user just specify the application name),
> my SNMP agent needs the process id in order to call the kill() function.
> Could you tell me how can I get the process id starting from the
application
> name (of course, in a C program)?

> Thanks.

> Giuseppe Greco


 
 
 

How to get the process id starting from the application name (in C)

Post by Dan Merc » Sat, 24 Jun 2000 04:00:00




> Hi to everybody.

> I wrote a SNMP agent that allows users to remotely start and stop
> applications. This agent must be portable on Windows NT and HP-UX. I
> completed the Windows NT implementation without problems. The HP-UX
> implementation if 90% OK. I have one small problem only. When a user want to
> remotely stop an application (the user just specify the application name),
> my SNMP agent needs the process id in order to call the kill() function.
> Could you tell me how can I get the process id starting from the application
> name (of course, in a C program)?

> Thanks.

> Giuseppe Greco

man pstat.  Look at the example code for pstat_getproc().

--
Dan Mercer

Opinions expressed herein are my own and may not represent those of my employer.

 
 
 

How to get the process id starting from the application name (in C)

Post by Giuseppe Grec » Sat, 24 Jun 2000 04:00:00


This will be not possible, since It is not possible to start the same
application twice. I have to write a function (for example bool
doesProcessExist(const tstring& moduleName)) that checks whether an
application has been already started or not.

Giuseppe


> What will you do if there are two processes with
> the same names but different PIDs?

> --



> > Hi to everybody.

> > I wrote a SNMP agent that allows users to remotely start and stop
> > applications. This agent must be portable on Windows NT and HP-UX. I
> > completed the Windows NT implementation without problems. The HP-UX
> > implementation if 90% OK. I have one small problem only. When a user
want
> to
> > remotely stop an application (the user just specify the application
name),
> > my SNMP agent needs the process id in order to call the kill() function.
> > Could you tell me how can I get the process id starting from the
> application
> > name (of course, in a C program)?

> > Thanks.

> > Giuseppe Greco

 
 
 

How to get the process id starting from the application name (in C)

Post by Giuseppe Grec » Sat, 24 Jun 2000 04:00:00


Thanks.

Giuseppe




> > Hi to everybody.

> > I wrote a SNMP agent that allows users to remotely start and stop
> > applications. This agent must be portable on Windows NT and HP-UX. I
> > completed the Windows NT implementation without problems. The HP-UX
> > implementation if 90% OK. I have one small problem only. When a user
want to
> > remotely stop an application (the user just specify the application
name),
> > my SNMP agent needs the process id in order to call the kill() function.
> > Could you tell me how can I get the process id starting from the
application
> > name (of course, in a C program)?

> > Thanks.

> > Giuseppe Greco

> man pstat.  Look at the example code for pstat_getproc().

> --
> Dan Mercer

> Opinions expressed herein are my own and may not represent those of my
employer.

 
 
 

How to get the process id starting from the application name (in C)

Post by Nate Eldredg » Sat, 24 Jun 2000 04:00:00



> This will be not possible, since It is not possible to start the same
> application twice. I have to write a function (for example bool
> doesProcessExist(const tstring& moduleName)) that checks whether an
> application has been already started or not.



> > What will you do if there are two processes with
> > the same names but different PIDs?

And what if someone starts another program with the same name?  This
is trivially easy to do.

--

Nate Eldredge

 
 
 

1. Capturing the Process ID of a Process started in Background in ksh

I believe that from the above code things should work as you expected.

The only thing I can think is that somehow a subshell was forked to
run the tail command.  Maybe you can look at what process '2433' is?

Can you post a complete script which shows the problem? Please edit
the script down before posting to give "the smallest script which
still exhibits the problem" Nobody'll bother reading anything more
than ten lines long :-)

Alexis

2. Red Hat 7.2 Beta lo (loopback) problem with new kernel - resolution

3. process id --> process name under Solar

4. NS 127.0.0.1 not reachable

5. Process id -> process name

6. New or Revised TAs on websco, 960113

7. process id's and their corresponding process names

8. Stunnel encryption level?

9. Determining process ID from process name

10. Process id of process started in "background" from script

11. Getting the process ID of a new process

12. process id's and process names