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

  1. #include <stddef.h>
  2. #include <stdlib.h>
  3. #include <unistd.h>
  4. #include <sys/types.h>
  5. #include <sys/wait.h>
  6.  
  7. /* Execute the command using this shell program. */
  8. #define SHELL "/bin/sh"
  9.  
  10. int
  11. my_system (const char *command)
  12. {
  13. int status;
  14. pid_t pid;
  15.  
  16. pid = fork ();
  17. if (pid == 0)
  18. {
  19. /* This is the child process. Execute the shell command. */
  20. execl (SHELL, SHELL, "-c", command, NULL);
  21. _exit (EXIT_FAILURE):
  22. }
  23. else if (pid < 0 )
  24. //the fork failed. Report failure
  25. status = -1;
  26. else
  27. // this is the parent process. It waits for the child process to complete
  28. if (waitpid (pid, &status, 0) != pid)
  29. status = -1;
  30. return status;
  31. }

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

  1. 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 - 11 Filters

GTU OS Program - 8