2. In apue.3e/environ a. Compile & link echoarg.c i. Run echoarg ii. Capture out
ID: 666165 • Letter: 2
Question
2. In apue.3e/environ
a. Compile & link echoarg.c
i. Run echoarg
ii. Capture output
b. How do you increase the number of arguments?
3. In apue.3e/exercises
a. Compile & link zombie.c
i. Run zombie
1. Capture output
2. Any zombie processes?
ii. Wait twenty minutes
1. Rerun zombie
a. Capture output
b. Any zombie processes?
2. If things changed, why?
b. Compile & link vfork3
i. Run vfork3
1. Capture output
2. What’s the structure address?
4. In apue.3e/proc
a. Compile & link fork1
i. Run fork1
ii. Capture output
b. Compile & link times1
i. Run times1 [e.g.: ./runtimes1 ls]
ii. Capture output
c. Compile & link wait1
i. Run wait1
ii. Capture output
iii. Where do the ‘Signals’ come from?
radii@Develop:~/CS510/apue.3e/proc$ ./wait1
normal termination, exit status = 7
abnormal termination, signal number = 6
abnormal termination, signal number = 8
radii@Develop:~/CS510/apue.3e/proc$
Explanation / Answer
exit(0);
apue
#include "apue.h" #include <errno.h> #include <fcntl.h> #include <sys/wait.h> int main(int argc, char *argv[]) { int fd; pid_t pid; char buf[5]; struct stat statbuf; if (argc != 2) { fprintf(stderr, "usage: %s filename ", argv[0]); exit(1); } if ((fd = open(argv[1], O_RDWR | O_CREAT | O_TRUNC, FILE_MODE)) < 0) err_sys("open error"); if (write(fd, "abcdef", 6) != 6) err_sys("write error"); /* turn on set-group-ID and turn off group-execute */ if (fstat(fd, &statbuf) < 0) err_sys("fstat error"); f (fchmod(fd, (statbuf.st_mode & ~S_IXGRP) | S_ISGID) < 0) err_sys("fchmod error"); TELL_WAIT(); if ((pid = fork()) < 0) { err_sys("fork error"); } else if (pid > 0) { /* parent */ /* write lock entire file */ if (write_lock(fd, 0, SEEK_SET, 0) < 0) err_sys("write_lock error"); TELL_CHILD(pid); if (waitpid(pid, NULL, 0) < 0) err_sys("waitpid error"); } else { /* child */ WAIT_PARENT(); /* wait for parent to set lock */ set_fl(fd, O_NONBLOCK); /* first let's see what error we get if region is locked */ if (read_lock(fd, 0, SEEK_SET, 0) != -1) /* no wait */ err_sys("child: read_lock succeeded"); printf("read_lock of already-locked region returns %d ", errno); /* now try to read the mandatory locked file */ if (lseek(fd, 0, SEEK_SET) == -1) err_sys("lseek error"); if (read(fd, buf, 2) < 0) err_ret("read failed (mandatory locking works)"); else printf("read OK (no mandatory locking), buf = %2.2s ", buf); }exit(0);
apue
#include "apue.h" static void my_exit1(void); static void my_exit2(void); int main(void) { if (atexit(my_exit2) != 0) err_sys("can't register my_exit2"); if (atexit(my_exit1) != 0) err_sys("can't register my_exit1"); if (atexit(my_exit1) != 0) err_sys("can't register my_exit1"); printf("main is done "); return(0); } static void my_exit1(void) { printf("first exit handler "); } static void my_exit2(void) { printf("second exit handler "); }Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.