Sale!

CECS-326: Operating Systems Lab 3 exec system calls

$30.00

Category:
5/5 - (2 votes)

CECS-326: Operating Systems
Lab 3
exec system calls
A process creates a child process and may want to change the program code the child is executing. There
are 6 system calls under the generalized heading exec. When the process issues any exec call, if the call is
successful, the existing process is overlaid with a new set of program code.
Call name argument pass env variables? search path?
execl list yes no
execv array yes no
execle list no no
execve array no no
execlp list yes yes
execvp array yes yes
# include <stdio.h>
# include <stdlib.h>
# include <sys/types.h>
# include <unistd.h>
void main(int argc, char *argv[])
{
if (argc > 1) {
execlp(“/bin/cat”, “cat”, argv[1], (char *) NULL);
perror (“exec failure”);
exit(1);
}
printf(“\n Usage: %s text_file\n”, *argv);
exit(1) ;
}
1. Check for program error, compile, and run. Observe the results.
2. Replace “cat” with other commands.
3. Replace contents of main function with
execvp(argv[1], &argv[1]);
perror(“exec failure”);
exit(1);
Compile, run, and observe results. Use other commands.
4. Replace contents of main function with the following (replace “yourfile.txt” with any existing text file in
your directory)
static char *new_argv[] = {“cat”,”yourfile.txt”, (char *) 0};
execvp(“/bin/cat”, new_argv);
perror(“exec failure”);
exit(1);
Compile, run, and observe results. Use commands other than “cat”.
END OF LAB 3

PlaceholderCECS-326: Operating Systems Lab 3 exec system calls
$30.00
Open chat
Need help?
Hello
Can we help?