man pstree
?pstree
command find out which processes are executing on your behalf. Hint: read pstree
's man page.fork
system call for? How do you distinguish between the parent and the child process?execve
system call for?wait()/waitpid()
system call when one of its child terminates?FYI:
<variable_name> = <variable_value>; export <variable_name>
<setenv variable_name> <variable_value>
For more info about these shells you can read a brief comparison compiled by Prof. José Magalhães Cruz
Write a program that:
Write a program that creates a child and a grand-child. Each process shall write its PID and that of its parent, as well as the termination code of its child, if it has any. The child and the grand-child shall terminate with code 2 and 3, respectively.
Hint: Develop this program gradually. E.g.:
Write a program that creates a process that compiles a C program whose name is passed on its command line. IMP.: Your program should execute gcc (/usr/bin/gcc)
, by invoking the execve()
system call with appropriate arguments. The parent should wait for the termination of its child.
Write a new version of the previous program, such that rather than creating a child process to execute the compiler, your program executes directly gcc
.