Implementation of mkdir command


/*Implementation of mkdir command */

#include<stdio.h>

#include<stdlib.h>

#include<sys/stat.h>

void usage(const char *myname)

{

printf(“\nUsage: %s <pathname> [<mode>]\n\n”, myname);

exit(1);

}

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

{

int mode;

if(argc<2)

usage(argv[0]);

if(argc==2)

mode = 0777;

elseif(sscanf(argv[2], “%o”, &mode==0)

{

printf(“%s : Invalid Mode\n”, argv[0]);

exit(1);

}

if(mkdir(argv[1], mode)== -1)

perror(argv[0]);

else

printf(“%s directory is created successfully”, argv[1]);

}

Implementation of Shared Memory Segment


//Shared Memory Segment

Program 1:

#include <sys/types.h>

#include <sys/ipc.h>

#include <sys/shm.h>

#include <stdio.h>

#include <sys/sem.h>

#define SHMSZ     27

main()

{

char c;

int semid,retval;

struct sembuf sop,sop1;

int shmid;

key_t key;

char *shm, *s;

key = 5678;

Read More »

C Program using UNIX System Call


/* illustrating IPC through pipe and fork system calls – Printing only odd numbers */

#include <stdio.h>

#include <sys/types.h>

#include <unistd.h>

#include <stdlib.h>

int main()

{

int pfd[2], i;

pid_t mypid;

if(pipe(pfd) < 0)

perror(“Pipe Error”);

if(!fork())

{

char data;

printf(“Enter a Number…\n”);

scanf(“%d”, &data);

write(pfd[1], &data, 1);

mypid = getpid();

printf(“I am process %d\n”, mypid);

printf(“My parent is process %d\n”, getppid());

printf(“Child Exiting…\n”);

Read More »