This problem will require you to write a program on a UNIX/Linux platform (most any will do) which will:
report a collection of process and thread information about itself to standard-out as described below
create a unnamed pipe
spawn a child process which will inherit access to the unnamed pipe
the parent process will now write a formatted text string into the pipe and then do a normal exit
the child process will report a collection of process and thread information about itself to standard-out as described below (just as the parent did)
the child process will then read the parent’s string from the pipe and write it to the standard output
the child process will then get its parent process ID again and write it to the standard output and then do a normal exit
The information generated from Process ID is: Process parent ID is: Real UID is:
Real GID is: Effective UID is: Effective GID is: Process initial thread priority:
all both parent and child should look like this: PID PPID RUID
RGID EUID EGID IT_PRIOR
All of your output must be prefixed by either CHILD:...... , so that it can be readily identified as to its source.
Below is helper file, please do this assignment by modifying it .
// need these include files
#include <sys/types.h
#includeunistd.h
#includestdio.h
#includeerrno.h
#includestdlib.h
#include <sys/resource.h
// need just a main function, no args
int main(void)
{
// some local variables
pid_t pid, ppid;
int ruid, rgid, euid, egid;
int priority;
char msg_buf[100];
intmsg_pipe[2];
// use the pipe() system call to create the pipe
if(pipe(msg_pipe) == -1){
perror("failed in Parent pipe creation:");
exit(7);
}
// use various system calls to collect and print process details
printf("\nThis is the Parent process report:\n");
pid = getpid();
ppid = getppid();
ruid = getuid();
euid = geteuid();
rgid = getgid();
egid = getegid();
priority = getpriority(PRIO_PROCESS, 0);
printf("\nPARENT PROG: Process ID is:\t\t%d\n\
PARENT PROC: Process parent ID is:\t%d\n\
PARENT PROC: Real UID is:\t\t%d\n\
PARENT PROC: Real GID is:\t\t%d\n\
PARENT PROC: Effective UID is:\t\t%d\n\
PARENT PROC: Effective GID is:\t\t%d\n\
PARENT PROC: Process priority is:\t%d\n\",
pid, ppid, ruid, rgid, euid, egid, priority);
printf("\nPARENT PROC: will now create child, write pipe,\n \
and do a normal termination\n");
// use the sprintf() call to build a message to write into the pipe
//
//
// now use the fork() call to create the child:
//
// format is:
//
// switch (pid = fork()){
// case -1: // if the call failes
//
// default: // this is the parent's case
// // parent must write message to pipe and
// // do a normal exit
//
// case 0: // this is the child's case
// // child must create and print report
// // child must read pipe message and print
// // a modified version of it to output
// // child must do a normal exit
read(msg_pipe[0], msg_buf, 100);
printf("CHILD PROC: parent's msg is %s\n" msg_buf);
printf("CHILD PROC: ### Goodbye ###\n");
exit(0);
} // switch and child end
}
/********************************************************************
This is a typical output from this assignment:
This is the Parent process report:
PARENT PROG: Process ID is: 15550
PARENT PROC: Process parent ID is: 26778
PARENT PROC: Real UID is: 1004
PARENT PROC: Real GID is: 4000
PARENT PROC: Effective UID is: 1004
PARENT PROC: Effective GID is: 4000
PARENT PROC: Process priority is: 0
PARENT PROC: will now create child, write pipe,
and do a normal termination
This is the Child process report:
CHILD PROC: Process ID is: 15551
CHILD PROC: Process parent ID is: 15550
CHILD PROC: Real UID is: 1004
CHILD PROC: Real GID is: 4000
CHILD PROC: Effective UID is: 1004
CHILD PROC: Effective GID is: 4000
CHILD PROC: Process prioroty is: 0
CHILD PROG: about to read pipe and report parent message:
PARENT PROG: created Child with 15551 PID
CHILD PROC: parent's msg is:
This is the pipe message from the parent with PID 15550
CHILD PROC: ### Goodbye ###
*********************************************************************/