c - clear screen using exec() in linux -
i trying write code clear screen using fork() through exec. referring http://man7.org/linux/man-pages/man3/exec.3.html manual confuse why not placing new image @ screen( mean clearing screen).
here attempt:
#include <stdio.h> #include <stdlib.h> #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <sys/wait.h> # include <curses.h> #define numargs 2 void main(int argc,char* argv[]) { pid_t pid; char * child_args[numargs] = {0,0}; if((pid=fork())==0){ exec();// clear screen } else{ wait(); } }
kindly correct me if wrong can solve problem.
you seems confused 2 different, unrelated things:
exec*()
,fork()
- clearing screen
fork
create new child process, duplicating state of current process @ same time.
exec
family of related functions, job replace current process another.
on unix systems, clearing screen done via ansi escape codes. please not print newlines in loop instead, that's totally cheap. if need portability between terminal emulators, can use libraries abstract task, such termcaps
or (n)curses
.
you mentioned using child process clear screen, suspect you're trying create kind of shell. anyway, can use fork()
create child, waitpid()
in parent function, , clear screen child, either directly, example fputs(stdout, "\033[2j")
, or exec*()
'in executable.
i don't know why don't clear screen parent, however.
Comments
Post a Comment