GTU OS Program - 15 Process creation

15. Write a program for process creation using C. (Use of gcc compiler)

Start by creating a new file called process.c using vim

Complete code of the program

#include <stddef.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/wait.h>

/* Execute the command using this shell program.  */
#define SHELL "/bin/sh"

int
my_system (const char *command)
{
        int status;
        pid_t pid;

        pid = fork ();
        if (pid == 0)
        {
                /* This is the child process.  Execute the shell command. */
                execl (SHELL, SHELL, "-c", command, NULL);
                _exit (EXIT_FAILURE):
        }
        else if (pid < 0 )
                //the fork failed. Report failure
                status = -1;
        else
                // this is the parent process. It waits for the child process to complete
                if (waitpid (pid, &status, 0) != pid)
                        status = -1;
        return status;
}

compiling the process.c file using gcc and executing it in terminal

tkanu025@hp:~/lab_solutions$ gcc process.c
Output
unfortunately I am facing a problem in installing gcc in my ubuntu. I will upload the output image as soon as that problem is resolved.


gtu os lab manual,

os GTU Practical,

operating system Programs,

Operating system shellscript programs,

Gtu study material 3140705,

OS 3140702,

os practical list process creation in C,

shell script programming,

gtu os practical,

os lab solution gtu

Comments

YouTube

Popular posts from this blog

GTU OOP Program - 18

GTU OS Program - 7

GTU OS Program - 3