Re: program calls system() gettind PID - slightly off topic

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]



On Thu, 2007-10-18 at 17:34 -0700, Garrick Staples wrote:
> On Thu, Oct 18, 2007 at 08:07:46PM -0400, Jerry Geis alleged:
> > I have a C program on centos. When I call system("some_program &");
> > how do I get the PID of the some_program?
> > 
> > I cant just list processes as there might be more than one some_program 
> > active.
> > I need to know the one that I just started.

Is each instance of "some_program" spawned from the same parent? If not,
the PPID of the child can be used to differentiate between the children.

> 
> You don't.  At least not by using system().
> 
> Use fork() and exec() and you will have the child pid.

Unfortunately (maybe), the environment that is provided by the system
call (the command interpreter is invoked - /etc/profile, /etc/bashrc et
al may come into play) is not established with fork and the exec* family
of commands. Programming effort may be needed if this is important.

Changing the invocation to some variation of

    "/bin/bash some_params some_program &"

might do the trick when using the fork/exec combo.

> <snip sig stuff>

--
Bill

_______________________________________________
CentOS mailing list
CentOS@xxxxxxxxxx
http://lists.centos.org/mailman/listinfo/centos

[Index of Archives]     [CentOS]     [CentOS Announce]     [CentOS Development]     [CentOS ARM Devel]     [CentOS Docs]     [CentOS Virtualization]     [Carrier Grade Linux]     [Linux Media]     [Asterisk]     [DCCP]     [Netdev]     [Xorg]     [Linux USB]
  Powered by Linux