Question

C program To develop a C program to implement a process system call. PROBLEM You are...

C program

To develop a C program to implement a process system call.

PROBLEM

You are to use the Ubuntu operating system to write a C program that creates a process to determine the identification of the current user of your computer. I mean if joe is the login of the current user of your computer your solution should return joe. Your solution must also provide the pid of both the parent and the child processes. You may use the fork(), getpid(), getppid(), as well as any of the exec() family of system calls.

HINT

The shell command whoami returns the current user of the system.

WHAT TO SUBMIT

You are to submit to Blackboard the following:

  1. Your source code, as well as
  2. any output produced by your solution that, clearly, states the following:
  1. The current user of the system, and
  2. information about both pids of the parent and the child processes. You are to use the following format to structure your output:
  1. The current user is: name-of-the-user
  2. Parent: My pid = pid-of-parent. I created child pid = pid-of-child
  3. Child: My pid = pid-of-child. My parent’s pid = pid-of-parent

Note: In b) Parent is to indicate that the output produced was generated by the parent process. In a similar way, in c) Child indicates that the output was generated by the child process.

0 0
Add a comment Improve this question Transcribed image text
Answer #1
fork.c
#include<stdio.h>
#include<unistd.h>
int main(){
        pid_t id;
        id = fork();
        if(id==0)
                printf("This is child process with id: %d\n",getpid());
        else if(id==-1)
                printf("Error in creating child process\n");
        else
                printf("This is parent process with id: %d\n",getpid());
        return 0;

exec.c

#include<stdio.h>
#include<unistd.h>

int main(){
        char *arg[]={"sh","shell.sh",NULL};
        printf("This is in execDemo.c . Running exec\n");
        execv("/bin/sh",arg);
        //execvp("./exec",arg);
        printf("After running exec\n");
        return 0;
}
#include<stdio.h>

int main(){
        printf("This is exec.c \n");
        return 0;
Add a comment
Know the answer?
Add Answer to:
C program To develop a C program to implement a process system call. PROBLEM You are...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Part 2. System Programming and Process Management You are asked to develop basic system programmi...

    Can someone help me create this program for Linux. Part 2. System Programming and Process Management You are asked to develop basic system programming including process creation and termination on a Linux platform in this part of programming project. You are asked to create multiple children processes to work under one parent process. In theory, children processes can do their own work separately or cooperatively to accomplish a task. In this assignment, these children processes simply print out a "hello"...

  • For Linux Operating System: Write a simple test program in C to find out PIDs of...

    For Linux Operating System: Write a simple test program in C to find out PIDs of ALL ancestor (i.e., parent, grandparent ) processes of the current process or a given process specified by a PID. A parent process's PID of a given process pid can be found in /proc/$pid/status

  • Q1) Including the initial parent process, how many processes are created by the program shown in...

    Q1) Including the initial parent process, how many processes are created by the program shown in Figure 1? Give an explanation for your answer. You can include an output statement to test and run the program. A sample output statement could be: printf("Testing......"); #include <stdio.h> #include <unistd.h> int main() { /*fork a child process*/ fork(); /*fork another child process*/ fork(); /*fork another child process*/ fork(); return 0; } Figure 1a - How many processes are created? Another version, now displaying...

  • Using either a UNIX or a Linux system, write a C program that forks a child...

    Using either a UNIX or a Linux system, write a C program that forks a child process that ultimately becomes a zombie process. Process states can be obtained from the command: ps -l The process states are shown below the S column; processes with a state of Z are zombies. The process identifier (pid) of the child process is listed in the PID column, and that of the parent is listed in the PPID column. Because you do not want...

  • Write a program in C using the fork() system call to do the following. The parent process (main program) forks a process...

    Write a program in C using the fork() system call to do the following. The parent process (main program) forks a process (CHILD 1) to compute and print the sum of first n integers where n is a variable shared between the parent and CHILD 1. It also forks another process (CHILD 2) that finds the sum of squares of the first n numbers where n is a variable it shares with the parent. Let CHILD 1 print “The sum...

  • Question 3: [2+2] a)What, to whom and how many values a fork system call returns? b)Assuming there is no syntax error, what is the output for the following C program for linux? All of you may need to put screenshot of your PC in

    Question 3:                  [2+2]a) What, to whom and how many values a fork system call returns? b) Assuming there is no syntax error, what is the output for the following C program for linux? All of you may need to put screenshot of your PC in which Terminal login must be your arid number.int main(){      pid_t  fork_return;        fork_return = fork(); if (fork_return == 0) {                  execlp("/bin/ls", "ls", NULL);                 printf("Child process ID: %d\n", getpid());      exit(0);        }        else { wait (NULL);                 printf("Parent process ID: %d\n", getpid());         }     return 0;}

  • I will provide, best rating. Please help me out understand how to solve part 2 of...

    I will provide, best rating. Please help me out understand how to solve part 2 of this problem. I'm not sure how to make this work using ONLY the exec-family. No system() function call. 1. Using either a UNIX or a Linux system, write a C program that forks a child process that ultimately becomes a zombie process. This zombie process must remain in the system for at least 10 seconds. Process states can be obtained from the command: ps...

  • Question 3: [2+2] a)What, to whom and how many values a fork system call returns? b)Assuming there is no syntax error, what is the output for the following C program for linux? All of you may need to put screenshot of your PC in

    Arid No is 19-arid-898Question 3:                  [2+2]a) What, to whom and how many values a fork system call returns? b) Assuming there is no syntax error, what is the output for the following C program for linux? All of you may need to put screenshot of your PC in which Terminal login must be your arid number.int main(){      pid_t  fork_return;        fork_return = fork(); if (fork_return == 0) {                  execlp("/bin/ls", "ls", NULL);                 printf("Child process ID: %d\n", getpid());      exit(0);        }        else { wait (NULL);                 printf("Parent process ID: %d\n",...

  • Linux & C code help with creating a child process and kills itself with SIGNAL. I...

    Linux & C code help with creating a child process and kills itself with SIGNAL. I provided most of the code, I need some help to finish. Please provide output screen shot as well. Thank you! A Process creates a child process. Child process will print out "hello 0" "hello 1" ..... 1 line per second. After a certain number of seconds(user input), it kills itself WITH signal mechanism ONLY, don't use exit() on the child. You can use alarm()...

  • (In Unix) Make a C program that creates a zombie child process. Both parent and child...

    (In Unix) Make a C program that creates a zombie child process. Both parent and child processes should execute the command "ps" to show the current process list. (1) ** Copy and paste your code in your report. ** (2) Take a screen shot that shows the defunct information generated by "ps".

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT