Menu
  • HOME
  • TAGS

waitpid - WIFEXITED returning 0 although child exited normally

c,fork,waitpid,execv

On Unix and Linux systems, the status returned from wait or waitpid (or any of the other wait variants) has this structure: bits meaning 0-6 signal number that caused child to exit, or 0177 if child stopped / continued or zero if child exited without a signal 7 1 if...

How can I pass the redirection operator '>' as an argument for execv?

c,echo,io-redirection,execv

First of all, redirection operators like > are interpreted by the shell, and mean nothing to execve(2) (or to echo, for that matter). You could try using system(3) instead, or you could set up the redirection yourself by opening the output file and setting standard out to the resulting file...

sprintf() command doesnt work

c,arrays,execv

char command1[50], command2[50]; // Added char *temp[] = {NULL, command1, command2, NULL}; // Modified temp[0]="sum"; sprintf(temp[1],"%f",x); // remove * sprintf(temp[2],"%f",y); // remove * You are not allocating to temp[1] and temp[2] and using those as destination buffer in sprintf and using incorrect * in sprint. You can use malloc to...

How to capture output of strace in C++ program

c++,linux,strace,execv

strace writes to stderr not to stdout, if you only want to capture the strace output just use stderr instead of stdout change the dup2 line like this dup2(pipes[1],2); If you want combined strace and ps output do this: dup2(pipes[1],1); dup2(pipes[1],2); if you want separated output you'll probably need to...