Instead of calling strace directly from the command line,
I want to write a program that runs strace for me to a given program. I tried to solve this for hours but I just don't know how to get it working.
I previously wrote a program that uses the same piece of code used below. Previous program simply duplicates the action of shell, and it records user input to a log file. Link: https://pastebin.com/Wf9TTZSM
All I did was take out the relevant codes, and change the user input to run "strace". But it doesn't work.
How can I get this working?
I'm getting the Seg fault (core dumped) error for below
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <stdlib.h>
int main ()
{
char *s = "strace ls";
char* separator = " ";
char* argv[64];
int argc = 0;
char* tmp;
printf("%s", s);
argv[argc] = strtok_r(s, separator, &tmp);
while( argv[argc] != NULL){
argc+=1;
argv[argc] = strtok_r(NULL, separator, &tmp);
}
execvp(argv[0],argv);
return 0;
}