Write a C Program to Display Time and Date Using Exec System Call

Aim:

To write a C Program to Display Time and Date Using Exec System Call.

Description:

EXEC is a functionality of an operating system that runs an executable file in the context of an already existing process, replacing the previous executable. This act is also referred to as an overlay. It is especially important in Unix-like systems, although exists elsewhere. As a new process is not created, the process identifier (PID) does not change, but the machine code, data, heap, and stack of the process are replaced by those of the new program.

Exercise:

    When a child fork for a parent process, write a program on how to use exec system calls.

Algorithm:

  • Step 1 − START.
  • Step 2 – Use the header file under the unistd.h
  • Step 3 − declare three integers char*program name char*arg1 and char*arg2
  • Step 4 − STOP.

Program:

#include <unistd.h>
int main(void) {
char *programName = "ls";
char *arg1 = "-lh";
char *arg2 = "/home";
execlp(programName, programName, arg1, arg2, NULL);
return 0;
}

Execution:

 Total 0

Result:

 Thus exec system call program was executed Successfully.

Leave a Comment