0% found this document useful (0 votes)
45 views

OS - Assignment 1

The document contains code for two C programs that use processes and forking. The first program uses fork() to create a child process, with the parent and child processes each printing different messages in a loop. The second program uses execvp() to launch the xeyes program, allocating memory for and populating an argument array to pass to execvp(). The document also includes instructions for compiling and running the programs.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
45 views

OS - Assignment 1

The document contains code for two C programs that use processes and forking. The first program uses fork() to create a child process, with the parent and child processes each printing different messages in a loop. The second program uses execvp() to launch the xeyes program, allocating memory for and populating an argument array to pass to execvp(). The document also includes instructions for compiling and running the programs.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

Question 1:

#include <stdio.h>

#include <unistd.h>

#include <sys/types.h>

int main() {

pid_t pid;

if ((pid = fork()) == 0) {

while (1) {

printf(“child’s return value %d: I want to play…\n”, pid);

} else {

while (1) {

printf(“parent’s return value %d: After the project…\n”, pid);

return 0;

Question 2:
#include <stdio.h>

#include <unistd.h>

#include <sys/types.h>

#define LB_SIZE 1024

int main(int argc, char *argv[]) {

char fullPathName[] = “/usr/X11R6/bin/xeyes”;

char *myArgv[LB_SIZE]; // an array of pointers

myArgv[0] = (char *) malloc(strlen(fullPathName) + 1);

strcpy(myArgv[0], fullPathName);
myArgv[1] = NULL; // last element should be a NULL pointer

execvp(fullPathName, myArgv);

exit(0); // should not be reached

}
Terminal Mai aa k us directory Mai ja k

gcc (filename).c

Phir

./a.out

&&&

sudo yum install gcc-c++

&&&

GCC install krne k liye

&&&

sudo yum -y install xorg-x11-apps

&&&

Q1:

#include <stdio.h>

#include <unistd.h>

#include <sys/types.h>

int main() {

pid_t pid;

if ((pid = fork()) == 0) {

while (1) {

printf("child’s return value %d: I want to play...\n", pid);

else {

while (1) { printf("parent’s return value %d: After the project...\n", pid);

return 0;

&&&
Q2:

#include <stdio.h>

#include <unistd.h>

#include <sys/types.h>

#include<string.h>

#include<stdlib.h>

#define LB_SIZE 1024

int main(int argc, char *argv[]) {

char fullPathName[] = "/usr/bin/xeyes";

char *myArgv[LB_SIZE];

// an array of pointers

myArgv[0] = (char *) malloc(strlen(fullPathName) + 1);

strcpy(myArgv[0], fullPathName);

myArgv[1] = NULL; // last element should be a NULL pointer

execvp(fullPathName, myArgv);

exit(0);

// should not be reached

&&&

install k baad xeyes &

You might also like