









Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
This page cannot be seen from the preview
Don't miss anything!










2008-12-1 cs3320 1
2008-12-1 cs3320 2
2008-12-1 cs3320 3
2008-12-1 cs3320 4
errno = 21 main: Is a directory errno = 29 main: Illegal seek main: Success
2008-12-1 cs3320 7
2008-12-1 cs3320 8
2008-12-1 cs3320 9 2008-12-1 cs3320 10
2008-12-1 cs3320 19
2008-12-1 cs3320 20
2008-12-1 cs3320 21
2008-12-1 cs3320 22
2008-12-1 cs3320 25
2008-12-1 cs3320 26
2008-12-1 cs3320 27
2008-12-1 cs3320 28
2008-12-1 cs3320 38
#include <stddef.h> #include <stdio.h> #include <sys/types.h> #include <dirent.h>
int main (void){ DIR *dp; struct dirent *ep;
dp = opendir ("./"); if (dp != NULL){ while (ep = readdir (dp)) puts (ep->d_name);
(void) closedir (dp); } else perror ("Couldn't open the directory");
return 0; }
2008-12-1 cs3320 39
2008-12-1 cs3320 40
#include linux/unistd.h #include <errno.h> int getdents(unsigned int fd, struct dirent *dirp, unsigned int count);
2008-12-1 cs3320 43
struct tm{ int tm_sec; /* Seconds. [0-60] (1 leap second) / int tm_min; / Minutes. [0-59] / int tm_hour; / Hours. [0-23] / int tm_mday; / Day. [1-31] / int tm_mon; / Month. [0-11] / int tm_year; / Year - 1900. / int tm_wday; / Day of week. [0-6] / int tm_yday; / Days in year.[0-365] / int tm_isdst; / DST. [-1/0/1]*/
#ifdef __USE_BSD long int tm_gmtoff; /* Seconds east of UTC. */ __const char tm_zone; / Timezone abbreviation. / #else long int __tm_gmtoff; / Seconds east of UTC. */ __const char __tm_zone; / Timezone abbreviation. */ #endif };
2008-12-1 cs3320 44
2008-12-1 cs3320 45
#include <stdio.h> main () { int pid; printf ("I'm the original process with PID %d and PPID %d.\n", getpid (), getppid ()); pid = fork (); /* Duplicate. Child & parent continue from here / if (pid != 0) / pid is non-zero, so I must be the parent */ { printf ("I'm the parent process with PID %d and PPID %d.\n", getpid () getppid ());
2008-12-1 cs3320 55
getpid (), getppid ()); printf ("My child's PID is %d\n", pid); } else /* pid is zero, so I must be the child / { printf ("I'm the child process with PID %d and PPID %d.\n", getpid (), getppid ()); } printf ("PID %d terminates.\n", getpid () ); / Both processes execute this */ }
2008-12-1 cs3320 56
2008-12-1 cs3320 57
#include <stdio.h> main () { int pid; printf ("I'm the original process with PID %d and PPID %d.\n", getpid (), getppid ()); pid = fork (); /* Duplicate. Child & parent continue from here / if (pid != 0) / Branch based on return value from fork () / { / pid is non-zero, so I must be the parent */ printf ("I'm the parent process with PID %d and PPID %d.\n", getpid (), getppid ()); i tf ("M hild' PID i %d\ " id)
2008-12-1 cs3320 58
printf ("My child's PID is %d\n", pid); } else { /* pid is zero, so I must be the child / sleep (5); / Make sure that the parent terminates first / printf ("I'm the child process with PID %d and PPID %d.\n", getpid (), getppid ()); } printf ("PID %d terminates.\n", getpid () ); / Both processes execute this */ }
2008-12-1 cs3320 61
2008-12-1 cs3320 62
2008-12-1 cs3320 63
2008-12-1 cs3320 64
2008-12-1 cs3320 73
2008-12-1 cs3320 74
2008-12-1 cs3320 75
#include <stdio.h> main () { printf ("I'm process %d and I'm about to exec an ls -l\n", getpid ()); execl ("/bin/ls", "ls", "-l", NULL); /* Execute ls */ printf ("This line should never be executed\n"); }
$ myexec I'm process 710 and I'm about to exec an ls l
2008-12-1 cs3320 76
I m process 710 and I m about to exec an ls -l total 38 -rw-rw-r-- 1 raj raj 187 Jul 22 20:24 alarm.c -rw-rw-r-- 1 raj raj 226 Jul 22 20:22 background.c -rw-rw-r-- 1 raj raj 284 Jul 22 20:22 mychdir.c -rw-rw-r-- 1 raj raj 2058 Jul 22 20:23 vount.c -rwxrwxr-x 1 raj raj 4174 Jul 24 12:08 zombie -rw-rw-r-- 1 raj raj 298 Jul 22 20:20 zombie.c
2008-12-1 cs3320 79
2008-12-1 cs3320 80
2008-12-1 cs3320 81
2008-12-1 cs3320 82