Getting frantic

A fork

Image via Wikipedia

I have my second, self-imposed, deadline for my MSc project looming and I haven’t written a word.

I have written lots of software and might be close to actually running the experiments I need to be able to write up. Though I have had a frantic evening trying to work out why one of the programs I had written was not working properly – and have settled on a kludge in the meantime.

The code calls fork():

int main(int argc, char* argv[])
if (argc < 2)
return 0; /* must supply a file to execute */
pid_t forker = fork();
if (forker == 0) {
//in the child process
if (argc == 3) {
ptrace(PTRACE_TRACEME, 0, 0, 0);
execlp(argv[1], argv[2]);
} else {
ptrace(PTRACE_TRACEME, 0, 0, 0);
execvp(argv[1], NULL);
return 0;

I had had this sort of code in:

char* childargs[argc - 1];
for (i = 1; i {
len = strlen(argv[i]);
childargs[i - 1] = malloc(len);
strcpy(childargs[i - 1], argv[i]);
execvp(childargs[0], childargs);


But it failed to run properly – anyone know why?

One thought on “Getting frantic

  1. Pingback: Progress on the MSc project | cartesian product

Comments are closed.