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]);

}

Advertisements

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 »