Unix Programming - system command

This is Interesting: Free IT Magazines  
Home > Archive > Unix Programming > September 2005 > system command





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author system command
niraj.kumar.ait@gmail.com

2005-09-26, 2:48 am

In a C program
I m executing this statement

system( "command x");

I want to know the pid of the "command x" .

TIA
niraj

Maxim Yegorushkin

2005-09-26, 2:48 am


niraj.kumar.ait@gmail.com wrote:
> In a C program
> I m executing this statement
>
> system( "command x");
>
> I want to know the pid of the "command x" .


By the time system() call returns control the "command x" has already
terminated, so pid would have no meaning to you.

Instead use fork()/exec() canonical sequence. You can get sources of
system() function from glibc and implement your own function in the
same manner.

Måns Rullgård

2005-09-26, 6:02 pm

"Maxim Yegorushkin" <maxim.yegorushkin@gmail.com> writes:

> niraj.kumar.ait@gmail.com wrote:
>
> By the time system() call returns control the "command x" has already
> terminated, so pid would have no meaning to you.


system("command x &") will start the command in the background. Doing
this is generally not a good idea, though.

--
Måns Rullgård
mru@inprovide.com
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com