Hi guys.
I have some shell scripts and I want to execute them via a C program.
This C program needs:
1- Get itself PID;
2- Get PID shell script;
3- Get all messages of shell scripts;
4- Knows the status of shell scripts;
I'm trying to use popen but I don't know how to use getpid() with popen.
I appreciate your help.

Follow below an example of my program:

#include <stdio.h>
#include <stdlib.h>
pid_t pid;
int main(int argc, char** argv)
{
int rc;
if ( argc == 2)
{
FILE* fp = 0;
char command [1024];
sprintf(command,"%s 2>&1",argv[1]);
printf("\nPID=%i\n",getpid());
if ((fp = popen( command, "r")))
{
char buffer[ 1024];
buffer[sizeof( buffer) - 1] = 0;
while (fgets( buffer, sizeof( buffer) - 1, fp))
fprintf(stdout,"\n====>%s", buffer);
if (WIFEXITED(rc = pclose(fp)))
{
if (WEXITSTATUS(rc))
printf("\nFinaliou COM erro\n");
else
printf("\nFinaliou SEM erro\n");
}
}
}
}