C program to make an exact copy of the current process in Ubundu

Hi All,

I am new to Linux and i need your for a program which makes the exact copy of the running process. I have got some codes but it only works for the first command and will not work for subsequent commands. Means it works for "ps" but will not work for "ps u". I have changed the code to accept the whole string but still the output for two word commands are not appearing. Hope some one can give me a help. My codes are below.

int main()
{
char command[80];
while (putchar('@'), gets(command)) {
if (fork())
wait(0); /* Parent */
else { /* Child */
execlp(command, command, 0);
printf("command not found\n");
exit(1);
}
}
}

First off -
execlp (or any exec call) clobbers the "original" process memory - it creates a brand new one. The old copy is gone for ever.

Next you have to pass the exec call a file with separated arguments
maybe something like execve "/bin/ksh", "-c", "usr/bin/grep 'hi' /path/to/somefile"
You are using a single command variable, it has to be parsed into the proper chunks.

fork() creates an exact copy, not exec.