SlideShare a Scribd company logo
Linux 12 January 2010 Knowx innovation 1
Unix Developed at Bell Labs in late 1960s Owned by AT&T at the time, which meant you had to buy it once AT&T figured out it was valuable Written in C (a high level language) Needs to be compiled to run Can be easily moved to a different system by re-compiling for new hardware 12 January 2010 Knowx innovation 2
Why Linux Entire OS source code is free Full freedom to study, modify, redistribute. No payments or restrictions. Kernel and many packages follow GNU GPL, LGPL or BSD style license. Powerful command line (shells) Multitasking, SMP, NUMA 12 January 2010 Knowx innovation 3
Protected memory True multiuser capabilities Filesystem choices:ext3, JFS, XFS, reiserFS Highly modular & scalable: From embedded systems to IBM mainframes  12 January 2010 Knowx innovation 4
distribution ,[object Object]
RedHat (related: Fedora, CentOS)
SUSE (related: OpenSUSE)
Mandriva
Slackware
Embedded Linuxes12 January 2010 Knowx innovation 5
GNU/Linux architecture 12 January 2010 Knowx innovation 6
Linux kernel Mediates access to the hardware and peripherals Shells  Provides user access to the kernel Applications  Provide the useful function for the operating system 12 January 2010 Knowx innovation 7
Kernel architecture 12 January 2010 Knowx innovation 8
Gnu compiler collection(gcc) Compiler and set of utilities to build binaries from high level source code. Standard for embedded systems development Since its supports so many different target architectures Supports a number of languages C, C++, ada, java, FORTRAN, Pascal 12 January 2010 Knowx innovation 9
Stage of compilation 12 January 2010 Knowx innovation 10
12 January 2010 Knowx innovation 11
makefile 12 January 2010 Knowx innovation 12
make utility uses a developer-created input file to describe the project built GNU uses the name Makefile as the default name for its input file. 12 January 2010 Knowx innovation 13
appexp : main.o app.o bar.o lib.o 	gcc –o appexp main.o app.o bar.o lib.o main.o : main.c lib.h app.h 	gcc –c -o main.o main.c app.o: app.c lib.h app.h 	gcc –c -o app.o app.c bar.o : bar.c lib.h 	gcc –c -o bar.o bar.c lib.o : lib.c lib.h 	gcc –c -o lib.o lib.c Line 1: is the rule The portion of the rule  before the colon is called  targetand after the colon is called  dependencies. 12 January 2010 Knowx innovation 14
File handling Accomplished through the standard C library We can create and manipulate ASCII text or binary files with the same API. API fopen, fclose, fwrite , fread, fseek, and rewind. 12 January 2010 Knowx innovation 15
fopen  Opening a file can also be the mechanism to create a file prototype: FILE * fopen(const char *filename,const char *mode) filename - file we wish to access or create mode – mode we wish to use FILE * - fopen returns the FILE pointer (FILE *)  12 January 2010 Knowx innovation 16
Example FILE *fin;  fin = fopen("inpfile.txt", "r");  12 January 2010 Knowx innovation 17
Program #include <stdio.h>  #define MYFILE "missing.txt"  main()  { FILE *fin;	  	fin = fopen( MYFILE, "r" );	/* Try to open the file for read */   	if (fin == (FILE *)0) 	/* Check for failure to open */  	{ printf(“error in opening file”); /* Emit an error message and exit */ exit(-1); }  	fclose( fin ); /* All was well, close the file */  } 12 January 2010 Knowx innovation 18
fread()  and  fwrite() Prototypes: size_t fread(void *ptr, size_t size, size_t nmemb,FILE *stream); size_t fwrite(const void *ptr, size_t size, size_t nmemb,FILE *stream); fseek() Prototype: int fseek (FILE * stream, long offset, int whence); Function allows to the new position given an index whence argument defines  12 January 2010 Knowx innovation 19
SEEK_SET   -   moves the file position to the position defined by 			offset SEEK_CUR  -moves the file position the number of bytes defined 			by offset from the current file position SEEK_END -     moves the file position to the number of bytes defined by 		offset from the end of the file rewind () Resets the file read pointer back to the start of the file Prototype void rewind (FILE * stream); 12 January 2010 Knowx innovation 20
Program #include <stdio.h> #define MAX_LINE 40  #define FILENAME "myfile.txt“ typedef struct  { int id; float x_coord; float y_coord; char name[MAX_LINE+1];  } MY_TYPE_T;  MY_TYPE_T object; int main()  { int i; FILE *fin;  fin = fopen( FILENAME, "r" );	 /* Open the input file */ 12 January 2010 Knowx innovation 21
 if (fin == (FILE *)0)  	exit(-1); fseek( fin, (2 * sizeof(MY_TYPE_T)), SEEK_SET ); /* Get the last entry */ fread( &object, sizeof(MY_TYPE_T), 1, fin );  printf("%d %f %f %s", object.id, object.x_coord, object.y_coord, 	object.name ); rewind( fin );	 /* Get the second to last entry */  fseek( fin, (1 * sizeof(MY_TYPE_T)), SEEK_SET ); fread( &object, sizeof(MY_TYPE_T), 1, fin ); printf("%d %f %f %s", object.id, object.x_coord, object.y_coord, 	object.name );  12 January 2010 Knowx innovation 22
/* Get the first entry */ rewind( fin );  fread( &object, sizeof(MY_TYPE_T), 1, fin );  printf("%d %f %f %s", object.id, object.x_coord, object.y_coord, 	object.name ); fclose( fin ); return 0;  }   12 January 2010 Knowx innovation 23
getpid()    - to get the current process ID. getppid()  - to get the parent process ID. getuid()    - to get the user ID. getgid()    - to get the group ID. 12 January 2010 Knowx innovation 24
Program #include <stdio.h>  #include <unistd.h>  #include <sys/types.h>  int main() { pid_t myPid;  pid_t myParentPid;  gid_t myGid;  uid_t myUid;  myPid = getpid();  myParentPid = getppid();  myGid = getgid(); 12 January 2010 Knowx innovation 25
myUid = getuid();  	printf( "my process id is %d", myPid );  	printf( "my parent's process id is %d", myParentPid ); printf( "my group id is %d", myGid ); printf( "my user id is %d", myUid ); return 0;  }  Output my process id is 10932. my parents process id is 10795 My group id is 500 My user id is 500 12 January 2010 Knowx innovation 26
Process api Fork Create a new child process Wait Suspend execution until a child processes exits Signal Install a new signal handler Exec Replace the current process image with a new process image 12 January 2010 Knowx innovation 27
Fork Creating new processes with in a given process. return value of fork is  greater than zero then in the parent context.	 Equal to zero then in the child context. less than zero then error occurred. 12 January 2010 Knowx innovation 28
Example pid_t pid; pid = fork(); if(pid>0) 	{/*parent context*/} else if (pid ==0) 	{/*child context*/} else {/*error occurred no child created*/} 12 January 2010 Knowx innovation 29
12 January 2010 Knowx innovation 30
Program #include <sys/types.h>  #include <sys/wait.h>  #include <unistd.h> #include <stdio.h>  #include <errno.h>  int main()  { pid_t ret;  int status, I, role = -1; 12 January 2010 Knowx innovation 31
ret = fork();  if (ret > 0)  { 	printf("Parent: This is the parent process (pid %d)", 	getpid());  	for (i = 0 ; i < 6 ; i++)  	{    printf("Parent: At count %d", i); sleep(1); } 	   ret = wait( &status );  	   role = 0;  	} else if (ret == 0) 	{    printf("Child: This is the child process (pid %d)", getpid());  12 January 2010 Knowx innovation 32
	for (i = 0 ; i < 6 ; i++)  	{ printf("Child: At count %d", i);  	sleep(1); } role = 1; 	 } else  	{  	   printf("Parent: Error trying to fork() (%d)", errno);  	} printf("%s: Exiting...", ((role == 0) ? "Parent" : "Child")); return 0;  }  12 January 2010 Knowx innovation 33
wait Suspend the calling process until a child process(created by this process) exits or until a signal is delivered. Prototype pid_t wait (int *status); 12 January 2010 Knowx innovation 34
Signal Install a signal handler for a process. Prototype sighandler_t signal (int signum, sighandler_t handler); SIGHUP  - hang up –commonly used to restart a task. SIGKILL - kill signal SIGINT   - interrupt from the keyboard SIGSTOP – stop process SIGQUIT – quit signal from keyboard 12 January 2010 Knowx innovation 35
Program #include <stdio.h>  #include <sys/types.h> #include <sys/wait.h> #include <unistd.h>  #include <signal.h> #include <errno.h>  void usr1_handler( int sig_num )  {  	printf( "Process (%d) got the SIGUSR1", getpid() );  } int main()  {  pid_t ret; int status role = -1;  signal( SIGUSR1, usr1_handler );  12 January 2010 Knowx innovation 36
ret = fork(); if (ret > 0)  {	 /* Parent Context */ printf( "Parent: This is the parent process (pid %d)", getpid() );  role = 0;  pause();  printf( "Parent: Awaiting child exit" ); ret = wait( &status ); } 12 January 2010 Knowx innovation 37
else if (ret == 0)  { /* Child Context */  printf( "Child: This is the child process (pid %d)", getpid() ); role = 1;  pause();  }  else  { /* Parent Context -- Error */  printf( "Parent: Error trying to fork() (%d)", errno );  } printf( "%s: Exiting...", ((role == 0) ? "Parent" : "Child") ); return 0; }  12 January 2010 Knowx innovation 38
exec Replaces the current process image altogether. Once the exec function replaces the current process, its pid is the same as the creating process Permits the current process context to be replace with the program specifies as the first argument. 12 January 2010 Knowx innovation 39
Example 	execl(“/bin/ls”,”ls”,”-la”,null); This command replaces the current process with the ls (list directory) Prototypes for the variants of exec int execl (const char *path,const char * arg, …,..) int execlp(const char *path,const char *arg,……) int execv(const char *path, char *const argv[]) int execvp(const char *file, char *const argv[]) 12 January 2010 Knowx innovation 40
Program for shell interpreter #include <sys/types.h>  #include <sys/wait.h> #include <unistd.h> #include <stdio.h> #include <stdlib.h>  #include <string.h>  #define MAX_LINE 80  int main()  { int status;  pid_t childpid; char cmd[MAX_LINE+1];  char *sret; 12 January 2010 Knowx innovation 41
 while (1)  { printf("mysh>");  sret = fgets( cmd, sizeof(cmd), stdin );  if (sret == NULL)  exit(-1); cmd[ strlen(cmd)-1] = 0;  if (!strncmp(cmd, "bye", 3))  exit(0); childpid = fork();  if (childpid == 0) 	{ execlp( cmd, cmd, 0 ); } else if (childpid > 0)  	{ waitpid( childpid, &status, 0 ); }  printf("");  }  return 0; }  12 January 2010 Knowx innovation 42
Message queues Messages are small collections of data (400 bytes, for example) that can be passed between cooperating programs through a message queue. Messages within a queue can be of different types, and any process with proper permissions can receive the messages. 12 January 2010 Knowx innovation 43
[object Object],API msgget(key_k key , int msgflg) the key which signifies the name given to the queue flags argument must contain the permission bits for the new queue IPC_CREAT if the queue is being created IPC_EXCL return an error if the message queue already exists Return the msgid Example  msgget(111 , 0666 | IPC_CREAT); 12 January 2010 Knowx innovation 44
Program #include <stdio.h>  #include <sys/msg.h> #define MY_MQ_ID 	111 int main() { int msgid; /* Create the message queue with the id MY_MQ_ID */  msgid = msgget( MY_MQ_ID, 0666 | IPC_CREAT );  if (msgid >= 0)  	{  printf( "Created a Message Queue %d", msgid );  } return 0; }  12 January 2010 Knowx innovation 45
[object Object],API int msgsnd (int msqid, const void *msgp, size_t msgsz, int msgflg);  Takes 4 parameters msqid is the queue id of the existing queue. msgp is the pointer that contains the address of the structure that holds the message and type. struct message { long mtype; //The message type.priority char mesg [MSGSZ];//The message is of length MSGSZ. };  12 January 2010 Knowx innovation 46
MSGSZ is the length of the message sent in bytes. MSGFLG specifies the action to be taken if one or more of the following are true. The number of bytes already in the queue is equal to msg_qbytes. The total number of messages on all queues on the system has reached a maximum limit Action to be taken If (msgflg & IPC_NOWAIT) is non-zero, the message will not be sent and the calling process will return immediately If (msgflg & IPC_NOWAIT) is 0, the calling process will suspend execution until one of the following occurs:  12 January 2010 Knowx innovation 47
Program #include <sys/types.h>  #include <sys/ipc.h>  #include <sys/msg.h> #include <stdio.h>  #include <string.h>  #define MSGSZ 128  typedef struct msgbuf   	/* will hold the message to be put in the queue */ { long mtype; 		/* priority of message */ char mtext[MSGSZ];	/* the message that is stored */  } message_buf;  main()  { int msqid;  int msgflg = IPC_CREAT | 0666;  key_t key; message_buf sbuf; size_t buf_length; key = 10; printf("Calling msgget with key %#lx and flag %#o",key,msgflg); 12 January 2010 Knowx innovation 48
/*A queue is created using the msget function with a key value 10 and the flag parameter being IPC_CREAT|06668 */  if ((msqid = msgget(key, msgflg )) < 0) { perror("msgget");  	exit(1); }  else  printf("msgget: msgget succeeded: msqid = %d", msqid);  sbuf.mtype = 1; 	/*setting the priority as 1 */ printf("msgget: msgget succeeded: msqid = %d", msqid); (void) strcpy(sbuf.mtext, "I am in the queue?");  /* copy the text "I am in the queue" into the array mtext which is message array */ printf("msgget: msgget succeeded: msqid = %d", msqid); 12 January 2010 Knowx innovation 49
 buf_length = strlen(sbuf.mtext) + 1 ;  /*sending the message with option IPC_NOWAIT */ if (msgsnd(msqid, &sbuf, buf_length, IPC_NOWAIT) < 0) {  printf ("%d, %d, %s, %d", msqid, sbuf.mtype, sbuf.mtext, 						buf_length);  	perror("msgsnd");  	exit(1);  }  else printf("Message: amp;quot;%samp;quot; Sent", sbuf.mtext);  exit(0);  } 12 January 2010 Knowx innovation 50
[object Object],API int msgrcv (int msqid, void *msgp, size_t msgsz, long msgtyp, int msgflg); Arguments- msqid is the queue id of the existing queue. msgp is the point to a receiving buffer large enough to hold the received message msgszthe maximum size of the received message 12 January 2010 Knowx innovation 51
program #include <sys/types.h>  #include <sys/ipc.h>  #include <sys/msg.h>  #include <stdio.h>  #define MSGSZ 128  typedef struct msgbuf /* structure that will hold the message obtained 			from the queue*/ {  	long mtype; 	/*priority of message */ 	char mtext[MSGSZ];	/*message that stored */ } message_buf; main()  { 12 January 2010 Knowx innovation 52
 int msqid;  key_t key;  message_buf rbuf;  key = 10; /*creating a queue with the key value 10, */ if ((msqid = msgget(key, 0666)) < 0) { perror("msgget");  exit(1); }  /*acquires the message from the queue into rbuf*/ if (msgrcv(msqid, &rbuf, MSGSZ, 1, 0) < 0)  	{ perror("msgrcv"); exit(1); } printf("%s", rbuf.mtext);  exit(0);  }  12 January 2010 Knowx innovation 53
[object Object],API msgctl(int msqid, int cmd, struct msqid_ds *buf) 3 Arguments  msqid is the queue id  cmd is a command constant *bufis a pointer to structure. Use to get the info about a message queue Set the info for a message queue Remove a message queue 12 January 2010 Knowx innovation 54
12 January 2010 Knowx innovation 55
Variable that is protected. It provides a means to restrict access to a resource that is shared amongst two or more processes Two operations are permitted , called acquire and release. 2 types of semaphore. Binary and Counting  12 January 2010 Knowx innovation 56 Semaphore
The signal notations P(semaphore variable) for wait V(semaphore variable) for signal 12 January 2010 Knowx innovation 57
A binary semaphore is a variable that can take only the values 0 and 1. Represents a single resource and therefore when one process has acquired it,others are blocked until it is released. P(sv) if sv greater than 0 , decrement sv.ifsvis zero suspend execution of the process V(sv) if other process has been suspended waiting for sv, make it resume.if no waiting, increment sv 12 January 2010 Knowx innovation 58 Binary semaphore
12 January 2010 Knowx innovation 59
Represent shared resources in quantities greater than one. It could represent the entire set of buffers by setting its value to the number of buffers available. Whenever the process acquires the semaphore, the value decrement . When the semaphore value reaches zero, process are blocked until it becomes a non zero. 12 January 2010 Knowx innovation 60 Counting semaphore
12 January 2010 Knowx innovation 61
[object Object],API semget( key_t key, int num_sems, int sem_flags) Key is the semaphore key Num_sems is the Semaphore count Flags  ,[object Object],API semop(int sem_id, struct sembuf *sem_ops,size_tnum_sem_ops) 12 January 2010 Knowx innovation 62
sem_id, is the semaphore identifier, as returned from semget. sem_ops, is a pointer to an array of structures, each of which will have at least the following members: Struct sembuf {short sem_num; short sem_op; short sem_flg; } 12 January 2010 Knowx innovation 63

More Related Content

What's hot

Unit 1
Unit 1Unit 1
Unit 1
siddr
 
Cisco IOS shellcode: All-in-one
Cisco IOS shellcode: All-in-oneCisco IOS shellcode: All-in-one
Cisco IOS shellcode: All-in-one
DefconRussia
 
Linux Security APIs and the Chromium Sandbox
Linux Security APIs and the Chromium SandboxLinux Security APIs and the Chromium Sandbox
Linux Security APIs and the Chromium Sandbox
Patricia Aas
 
PE Packers Used in Malicious Software - Part 1
PE Packers Used in Malicious Software - Part 1PE Packers Used in Malicious Software - Part 1
PE Packers Used in Malicious Software - Part 1
amiable_indian
 
Usp
UspUsp
Unix Programming with Perl
Unix Programming with PerlUnix Programming with Perl
Unix Programming with Perl
Kazuho Oku
 
Python for-unix-and-linux-system-administration
Python for-unix-and-linux-system-administrationPython for-unix-and-linux-system-administration
Python for-unix-and-linux-system-administration
Victor Marcelino
 
various tricks for remote linux exploits  by Seok-Ha Lee (wh1ant)
various tricks for remote linux exploits  by Seok-Ha Lee (wh1ant)various tricks for remote linux exploits  by Seok-Ha Lee (wh1ant)
various tricks for remote linux exploits  by Seok-Ha Lee (wh1ant)
CODE BLUE
 
Ilfak Guilfanov - Decompiler internals: Microcode [rooted2018]
Ilfak Guilfanov - Decompiler internals: Microcode [rooted2018]Ilfak Guilfanov - Decompiler internals: Microcode [rooted2018]
Ilfak Guilfanov - Decompiler internals: Microcode [rooted2018]
RootedCON
 
Linux 系統程式--第一章 i/o 函式
Linux 系統程式--第一章 i/o 函式Linux 系統程式--第一章 i/o 函式
Linux 系統程式--第一章 i/o 函式
艾鍗科技
 
OpenGurukul : Language : PHP
OpenGurukul : Language : PHPOpenGurukul : Language : PHP
OpenGurukul : Language : PHP
Open Gurukul
 
Facebook Glow Compiler のソースコードをグダグダ語る会
Facebook Glow Compiler のソースコードをグダグダ語る会Facebook Glow Compiler のソースコードをグダグダ語る会
Facebook Glow Compiler のソースコードをグダグダ語る会
Mr. Vengineer
 
Google Edge TPUで TensorFlow Liteを使った時に 何をやっているのかを妄想してみる 2 「エッジAIモダン計測制御の世界」オ...
Google Edge TPUで TensorFlow Liteを使った時に 何をやっているのかを妄想してみる 2  「エッジAIモダン計測制御の世界」オ...Google Edge TPUで TensorFlow Liteを使った時に 何をやっているのかを妄想してみる 2  「エッジAIモダン計測制御の世界」オ...
Google Edge TPUで TensorFlow Liteを使った時に 何をやっているのかを妄想してみる 2 「エッジAIモダン計測制御の世界」オ...
Mr. Vengineer
 
penetration testing - black box type.
penetration testing - black box type.penetration testing - black box type.
penetration testing - black box type.
luigi capuzzello
 
Pycon Sec
Pycon SecPycon Sec
Pycon Sec
guesta762e4
 
Using the Power to Prove
Using the Power to ProveUsing the Power to Prove
Using the Power to Prove
Kazuho Oku
 
Hardware Open Source
Hardware Open SourceHardware Open Source
Hardware Open Source
Tiago Maluta
 
iCloud keychain
iCloud keychainiCloud keychain
iCloud keychain
Alexey Troshichev
 
PVS-Studio, a solution for resource intensive applications development
PVS-Studio, a solution for resource intensive applications developmentPVS-Studio, a solution for resource intensive applications development
PVS-Studio, a solution for resource intensive applications development
OOO "Program Verification Systems"
 
Kernel Recipes 2019 - GNU poke, an extensible editor for structured binary data
Kernel Recipes 2019 - GNU poke, an extensible editor for structured binary dataKernel Recipes 2019 - GNU poke, an extensible editor for structured binary data
Kernel Recipes 2019 - GNU poke, an extensible editor for structured binary data
Anne Nicolas
 

What's hot (20)

Unit 1
Unit 1Unit 1
Unit 1
 
Cisco IOS shellcode: All-in-one
Cisco IOS shellcode: All-in-oneCisco IOS shellcode: All-in-one
Cisco IOS shellcode: All-in-one
 
Linux Security APIs and the Chromium Sandbox
Linux Security APIs and the Chromium SandboxLinux Security APIs and the Chromium Sandbox
Linux Security APIs and the Chromium Sandbox
 
PE Packers Used in Malicious Software - Part 1
PE Packers Used in Malicious Software - Part 1PE Packers Used in Malicious Software - Part 1
PE Packers Used in Malicious Software - Part 1
 
Usp
UspUsp
Usp
 
Unix Programming with Perl
Unix Programming with PerlUnix Programming with Perl
Unix Programming with Perl
 
Python for-unix-and-linux-system-administration
Python for-unix-and-linux-system-administrationPython for-unix-and-linux-system-administration
Python for-unix-and-linux-system-administration
 
various tricks for remote linux exploits  by Seok-Ha Lee (wh1ant)
various tricks for remote linux exploits  by Seok-Ha Lee (wh1ant)various tricks for remote linux exploits  by Seok-Ha Lee (wh1ant)
various tricks for remote linux exploits  by Seok-Ha Lee (wh1ant)
 
Ilfak Guilfanov - Decompiler internals: Microcode [rooted2018]
Ilfak Guilfanov - Decompiler internals: Microcode [rooted2018]Ilfak Guilfanov - Decompiler internals: Microcode [rooted2018]
Ilfak Guilfanov - Decompiler internals: Microcode [rooted2018]
 
Linux 系統程式--第一章 i/o 函式
Linux 系統程式--第一章 i/o 函式Linux 系統程式--第一章 i/o 函式
Linux 系統程式--第一章 i/o 函式
 
OpenGurukul : Language : PHP
OpenGurukul : Language : PHPOpenGurukul : Language : PHP
OpenGurukul : Language : PHP
 
Facebook Glow Compiler のソースコードをグダグダ語る会
Facebook Glow Compiler のソースコードをグダグダ語る会Facebook Glow Compiler のソースコードをグダグダ語る会
Facebook Glow Compiler のソースコードをグダグダ語る会
 
Google Edge TPUで TensorFlow Liteを使った時に 何をやっているのかを妄想してみる 2 「エッジAIモダン計測制御の世界」オ...
Google Edge TPUで TensorFlow Liteを使った時に 何をやっているのかを妄想してみる 2  「エッジAIモダン計測制御の世界」オ...Google Edge TPUで TensorFlow Liteを使った時に 何をやっているのかを妄想してみる 2  「エッジAIモダン計測制御の世界」オ...
Google Edge TPUで TensorFlow Liteを使った時に 何をやっているのかを妄想してみる 2 「エッジAIモダン計測制御の世界」オ...
 
penetration testing - black box type.
penetration testing - black box type.penetration testing - black box type.
penetration testing - black box type.
 
Pycon Sec
Pycon SecPycon Sec
Pycon Sec
 
Using the Power to Prove
Using the Power to ProveUsing the Power to Prove
Using the Power to Prove
 
Hardware Open Source
Hardware Open SourceHardware Open Source
Hardware Open Source
 
iCloud keychain
iCloud keychainiCloud keychain
iCloud keychain
 
PVS-Studio, a solution for resource intensive applications development
PVS-Studio, a solution for resource intensive applications developmentPVS-Studio, a solution for resource intensive applications development
PVS-Studio, a solution for resource intensive applications development
 
Kernel Recipes 2019 - GNU poke, an extensible editor for structured binary data
Kernel Recipes 2019 - GNU poke, an extensible editor for structured binary dataKernel Recipes 2019 - GNU poke, an extensible editor for structured binary data
Kernel Recipes 2019 - GNU poke, an extensible editor for structured binary data
 

Viewers also liked

Better Search UX
Better Search UXBetter Search UX
Better Search UX
Ravi Mynampaty
 
What to Feed Your Search Engine: The Evolution of Search Analytics at HBS
What to Feed Your Search Engine:  The Evolution of Search Analytics at HBSWhat to Feed Your Search Engine:  The Evolution of Search Analytics at HBS
What to Feed Your Search Engine: The Evolution of Search Analytics at HBS
Ravi Mynampaty
 
Developing a Search & Findability Practice for the Enterprise
Developing a Search & Findability Practice for the EnterpriseDeveloping a Search & Findability Practice for the Enterprise
Developing a Search & Findability Practice for the Enterprise
Ravi Mynampaty
 
Citiscapes
CitiscapesCitiscapes
Citiscapes
miguelvaldivieso
 
How we spiked the HBS water supply with Solr
How we spiked the HBS water supply with Solr How we spiked the HBS water supply with Solr
How we spiked the HBS water supply with Solr
Ravi Mynampaty
 
Clustering Search Log Data
Clustering Search Log DataClustering Search Log Data
Clustering Search Log Data
Ravi Mynampaty
 
Go Creations A Profile
Go Creations A ProfileGo Creations A Profile
Go Creations A Profile
chasealive
 
How We Incrementally Improved Search
How We Incrementally Improved SearchHow We Incrementally Improved Search
How We Incrementally Improved Search
Ravi Mynampaty
 
Trabajo Oscar
Trabajo OscarTrabajo Oscar
Trabajo Oscar
racso1687
 
Trabajo
TrabajoTrabajo
Timers
TimersTimers
Timers
afzal pa
 
I D
I DI D
Clustering as presented at UX Poland 2013
Clustering as presented at UX Poland 2013Clustering as presented at UX Poland 2013
Clustering as presented at UX Poland 2013
Ravi Mynampaty
 
Arrays
ArraysArrays
Arrays
afzal pa
 
Building a Solr-driven Web Portal
Building a Solr-driven Web PortalBuilding a Solr-driven Web Portal
Building a Solr-driven Web Portal
Ravi Mynampaty
 
Findability Standards
Findability StandardsFindability Standards
Findability Standards
Ravi Mynampaty
 

Viewers also liked (17)

Better Search UX
Better Search UXBetter Search UX
Better Search UX
 
What to Feed Your Search Engine: The Evolution of Search Analytics at HBS
What to Feed Your Search Engine:  The Evolution of Search Analytics at HBSWhat to Feed Your Search Engine:  The Evolution of Search Analytics at HBS
What to Feed Your Search Engine: The Evolution of Search Analytics at HBS
 
Developing a Search & Findability Practice for the Enterprise
Developing a Search & Findability Practice for the EnterpriseDeveloping a Search & Findability Practice for the Enterprise
Developing a Search & Findability Practice for the Enterprise
 
Citiscapes
CitiscapesCitiscapes
Citiscapes
 
How we spiked the HBS water supply with Solr
How we spiked the HBS water supply with Solr How we spiked the HBS water supply with Solr
How we spiked the HBS water supply with Solr
 
Clustering Search Log Data
Clustering Search Log DataClustering Search Log Data
Clustering Search Log Data
 
Go Creations A Profile
Go Creations A ProfileGo Creations A Profile
Go Creations A Profile
 
How We Incrementally Improved Search
How We Incrementally Improved SearchHow We Incrementally Improved Search
How We Incrementally Improved Search
 
Trabajo Oscar
Trabajo OscarTrabajo Oscar
Trabajo Oscar
 
Trabajo
TrabajoTrabajo
Trabajo
 
Timers
TimersTimers
Timers
 
I D
I DI D
I D
 
wot pdf
wot pdfwot pdf
wot pdf
 
Clustering as presented at UX Poland 2013
Clustering as presented at UX Poland 2013Clustering as presented at UX Poland 2013
Clustering as presented at UX Poland 2013
 
Arrays
ArraysArrays
Arrays
 
Building a Solr-driven Web Portal
Building a Solr-driven Web PortalBuilding a Solr-driven Web Portal
Building a Solr-driven Web Portal
 
Findability Standards
Findability StandardsFindability Standards
Findability Standards
 

Similar to Linux

Python ppt
Python pptPython ppt
Python ppt
Rohit Verma
 
Linux Systems Programming: Inter Process Communication (IPC) using Pipes
Linux Systems Programming: Inter Process Communication (IPC) using PipesLinux Systems Programming: Inter Process Communication (IPC) using Pipes
Linux Systems Programming: Inter Process Communication (IPC) using Pipes
RashidFaridChishti
 
Linux IO
Linux IOLinux IO
Linux IO
Liran Ben Haim
 
pcDuino Presentation at SparkFun
pcDuino Presentation at SparkFunpcDuino Presentation at SparkFun
pcDuino Presentation at SparkFun
Jingfeng Liu
 
Pythonpresent
PythonpresentPythonpresent
Pythonpresent
Chui-Wen Chiu
 
Information track presentation_final
Information track presentation_finalInformation track presentation_final
Information track presentation_final
Kazuki Omo
 
Xdebug
XdebugXdebug
Os lab final
Os lab finalOs lab final
Os lab final
LakshmiSarvani6
 
MicroPython for LEGO Spike - introduction
MicroPython for LEGO Spike - introductionMicroPython for LEGO Spike - introduction
MicroPython for LEGO Spike - introduction
sdoro58
 
EKON 25 Python4Delphi_mX4
EKON 25 Python4Delphi_mX4EKON 25 Python4Delphi_mX4
EKON 25 Python4Delphi_mX4
Max Kleiner
 
Jordan Hubbard Talk @ LISA
Jordan Hubbard Talk @ LISAJordan Hubbard Talk @ LISA
Jordan Hubbard Talk @ LISA
guest4c923d
 
11_UNIX_Processes_Including_Select.ppt
11_UNIX_Processes_Including_Select.ppt11_UNIX_Processes_Including_Select.ppt
11_UNIX_Processes_Including_Select.ppt
SIDDHARTHANANDCSE202
 
Book
BookBook
Book
luis_lmro
 
Python GTK (Hacking Camp)
Python GTK (Hacking Camp)Python GTK (Hacking Camp)
Python GTK (Hacking Camp)
Yuren Ju
 
Lab Handson: Power your Creations with Intel Edison!
Lab Handson: Power your Creations with Intel Edison!Lab Handson: Power your Creations with Intel Edison!
Lab Handson: Power your Creations with Intel Edison!
Codemotion
 
DeviceHub - First steps using Intel Edison
DeviceHub - First steps using Intel EdisonDeviceHub - First steps using Intel Edison
DeviceHub - First steps using Intel Edison
Gabriel Arnautu
 
Using Flow-based programming to write tools and workflows for Scientific Comp...
Using Flow-based programming to write tools and workflows for Scientific Comp...Using Flow-based programming to write tools and workflows for Scientific Comp...
Using Flow-based programming to write tools and workflows for Scientific Comp...
Samuel Lampa
 
maXbox starter30 Web of Things
maXbox starter30 Web of ThingsmaXbox starter30 Web of Things
maXbox starter30 Web of Things
Max Kleiner
 
File management
File managementFile management
File management
Mohammed Sikander
 
Python-GTK
Python-GTKPython-GTK
Python-GTK
Yuren Ju
 

Similar to Linux (20)

Python ppt
Python pptPython ppt
Python ppt
 
Linux Systems Programming: Inter Process Communication (IPC) using Pipes
Linux Systems Programming: Inter Process Communication (IPC) using PipesLinux Systems Programming: Inter Process Communication (IPC) using Pipes
Linux Systems Programming: Inter Process Communication (IPC) using Pipes
 
Linux IO
Linux IOLinux IO
Linux IO
 
pcDuino Presentation at SparkFun
pcDuino Presentation at SparkFunpcDuino Presentation at SparkFun
pcDuino Presentation at SparkFun
 
Pythonpresent
PythonpresentPythonpresent
Pythonpresent
 
Information track presentation_final
Information track presentation_finalInformation track presentation_final
Information track presentation_final
 
Xdebug
XdebugXdebug
Xdebug
 
Os lab final
Os lab finalOs lab final
Os lab final
 
MicroPython for LEGO Spike - introduction
MicroPython for LEGO Spike - introductionMicroPython for LEGO Spike - introduction
MicroPython for LEGO Spike - introduction
 
EKON 25 Python4Delphi_mX4
EKON 25 Python4Delphi_mX4EKON 25 Python4Delphi_mX4
EKON 25 Python4Delphi_mX4
 
Jordan Hubbard Talk @ LISA
Jordan Hubbard Talk @ LISAJordan Hubbard Talk @ LISA
Jordan Hubbard Talk @ LISA
 
11_UNIX_Processes_Including_Select.ppt
11_UNIX_Processes_Including_Select.ppt11_UNIX_Processes_Including_Select.ppt
11_UNIX_Processes_Including_Select.ppt
 
Book
BookBook
Book
 
Python GTK (Hacking Camp)
Python GTK (Hacking Camp)Python GTK (Hacking Camp)
Python GTK (Hacking Camp)
 
Lab Handson: Power your Creations with Intel Edison!
Lab Handson: Power your Creations with Intel Edison!Lab Handson: Power your Creations with Intel Edison!
Lab Handson: Power your Creations with Intel Edison!
 
DeviceHub - First steps using Intel Edison
DeviceHub - First steps using Intel EdisonDeviceHub - First steps using Intel Edison
DeviceHub - First steps using Intel Edison
 
Using Flow-based programming to write tools and workflows for Scientific Comp...
Using Flow-based programming to write tools and workflows for Scientific Comp...Using Flow-based programming to write tools and workflows for Scientific Comp...
Using Flow-based programming to write tools and workflows for Scientific Comp...
 
maXbox starter30 Web of Things
maXbox starter30 Web of ThingsmaXbox starter30 Web of Things
maXbox starter30 Web of Things
 
File management
File managementFile management
File management
 
Python-GTK
Python-GTKPython-GTK
Python-GTK
 

Recently uploaded

Main Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docxMain Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docx
adhitya5119
 
Top five deadliest dog breeds in America
Top five deadliest dog breeds in AmericaTop five deadliest dog breeds in America
Top five deadliest dog breeds in America
Bisnar Chase Personal Injury Attorneys
 
S1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptxS1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptx
tarandeep35
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
Peter Windle
 
Smart-Money for SMC traders good time and ICT
Smart-Money for SMC traders good time and ICTSmart-Money for SMC traders good time and ICT
Smart-Money for SMC traders good time and ICT
simonomuemu
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
heathfieldcps1
 
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdfবাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
eBook.com.bd (প্রয়োজনীয় বাংলা বই)
 
Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
Scholarhat
 
How to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold MethodHow to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold Method
Celine George
 
MARY JANE WILSON, A “BOA MÃE” .
MARY JANE WILSON, A “BOA MÃE”           .MARY JANE WILSON, A “BOA MÃE”           .
MARY JANE WILSON, A “BOA MÃE” .
Colégio Santa Teresinha
 
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective UpskillingYour Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Excellence Foundation for South Sudan
 
A Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdfA Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdf
Jean Carlos Nunes Paixão
 
PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.
Dr. Shivangi Singh Parihar
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
Nguyen Thanh Tu Collection
 
PIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf IslamabadPIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf Islamabad
AyyanKhan40
 
South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
Academy of Science of South Africa
 
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptxChapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Mohd Adib Abd Muin, Senior Lecturer at Universiti Utara Malaysia
 
Digital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental DesignDigital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental Design
amberjdewit93
 
World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024
ak6969907
 
The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
Israel Genealogy Research Association
 

Recently uploaded (20)

Main Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docxMain Java[All of the Base Concepts}.docx
Main Java[All of the Base Concepts}.docx
 
Top five deadliest dog breeds in America
Top five deadliest dog breeds in AmericaTop five deadliest dog breeds in America
Top five deadliest dog breeds in America
 
S1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptxS1-Introduction-Biopesticides in ICM.pptx
S1-Introduction-Biopesticides in ICM.pptx
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
 
Smart-Money for SMC traders good time and ICT
Smart-Money for SMC traders good time and ICTSmart-Money for SMC traders good time and ICT
Smart-Money for SMC traders good time and ICT
 
The basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptxThe basics of sentences session 5pptx.pptx
The basics of sentences session 5pptx.pptx
 
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdfবাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
বাংলাদেশ অর্থনৈতিক সমীক্ষা (Economic Review) ২০২৪ UJS App.pdf
 
Azure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHatAzure Interview Questions and Answers PDF By ScholarHat
Azure Interview Questions and Answers PDF By ScholarHat
 
How to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold MethodHow to Build a Module in Odoo 17 Using the Scaffold Method
How to Build a Module in Odoo 17 Using the Scaffold Method
 
MARY JANE WILSON, A “BOA MÃE” .
MARY JANE WILSON, A “BOA MÃE”           .MARY JANE WILSON, A “BOA MÃE”           .
MARY JANE WILSON, A “BOA MÃE” .
 
Your Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective UpskillingYour Skill Boost Masterclass: Strategies for Effective Upskilling
Your Skill Boost Masterclass: Strategies for Effective Upskilling
 
A Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdfA Independência da América Espanhola LAPBOOK.pdf
A Independência da América Espanhola LAPBOOK.pdf
 
PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.PCOS corelations and management through Ayurveda.
PCOS corelations and management through Ayurveda.
 
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
BÀI TẬP BỔ TRỢ TIẾNG ANH 8 CẢ NĂM - GLOBAL SUCCESS - NĂM HỌC 2023-2024 (CÓ FI...
 
PIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf IslamabadPIMS Job Advertisement 2024.pdf Islamabad
PIMS Job Advertisement 2024.pdf Islamabad
 
South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
 
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptxChapter 4 - Islamic Financial Institutions in Malaysia.pptx
Chapter 4 - Islamic Financial Institutions in Malaysia.pptx
 
Digital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental DesignDigital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental Design
 
World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024
 
The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
 

Linux

  • 1. Linux 12 January 2010 Knowx innovation 1
  • 2. Unix Developed at Bell Labs in late 1960s Owned by AT&T at the time, which meant you had to buy it once AT&T figured out it was valuable Written in C (a high level language) Needs to be compiled to run Can be easily moved to a different system by re-compiling for new hardware 12 January 2010 Knowx innovation 2
  • 3. Why Linux Entire OS source code is free Full freedom to study, modify, redistribute. No payments or restrictions. Kernel and many packages follow GNU GPL, LGPL or BSD style license. Powerful command line (shells) Multitasking, SMP, NUMA 12 January 2010 Knowx innovation 3
  • 4. Protected memory True multiuser capabilities Filesystem choices:ext3, JFS, XFS, reiserFS Highly modular & scalable: From embedded systems to IBM mainframes 12 January 2010 Knowx innovation 4
  • 5.
  • 10. Embedded Linuxes12 January 2010 Knowx innovation 5
  • 11. GNU/Linux architecture 12 January 2010 Knowx innovation 6
  • 12. Linux kernel Mediates access to the hardware and peripherals Shells Provides user access to the kernel Applications Provide the useful function for the operating system 12 January 2010 Knowx innovation 7
  • 13. Kernel architecture 12 January 2010 Knowx innovation 8
  • 14. Gnu compiler collection(gcc) Compiler and set of utilities to build binaries from high level source code. Standard for embedded systems development Since its supports so many different target architectures Supports a number of languages C, C++, ada, java, FORTRAN, Pascal 12 January 2010 Knowx innovation 9
  • 15. Stage of compilation 12 January 2010 Knowx innovation 10
  • 16. 12 January 2010 Knowx innovation 11
  • 17. makefile 12 January 2010 Knowx innovation 12
  • 18. make utility uses a developer-created input file to describe the project built GNU uses the name Makefile as the default name for its input file. 12 January 2010 Knowx innovation 13
  • 19. appexp : main.o app.o bar.o lib.o gcc –o appexp main.o app.o bar.o lib.o main.o : main.c lib.h app.h gcc –c -o main.o main.c app.o: app.c lib.h app.h gcc –c -o app.o app.c bar.o : bar.c lib.h gcc –c -o bar.o bar.c lib.o : lib.c lib.h gcc –c -o lib.o lib.c Line 1: is the rule The portion of the rule before the colon is called targetand after the colon is called dependencies. 12 January 2010 Knowx innovation 14
  • 20. File handling Accomplished through the standard C library We can create and manipulate ASCII text or binary files with the same API. API fopen, fclose, fwrite , fread, fseek, and rewind. 12 January 2010 Knowx innovation 15
  • 21. fopen Opening a file can also be the mechanism to create a file prototype: FILE * fopen(const char *filename,const char *mode) filename - file we wish to access or create mode – mode we wish to use FILE * - fopen returns the FILE pointer (FILE *) 12 January 2010 Knowx innovation 16
  • 22. Example FILE *fin; fin = fopen("inpfile.txt", "r"); 12 January 2010 Knowx innovation 17
  • 23. Program #include <stdio.h> #define MYFILE "missing.txt" main() { FILE *fin; fin = fopen( MYFILE, "r" ); /* Try to open the file for read */ if (fin == (FILE *)0) /* Check for failure to open */ { printf(“error in opening file”); /* Emit an error message and exit */ exit(-1); } fclose( fin ); /* All was well, close the file */ } 12 January 2010 Knowx innovation 18
  • 24. fread() and fwrite() Prototypes: size_t fread(void *ptr, size_t size, size_t nmemb,FILE *stream); size_t fwrite(const void *ptr, size_t size, size_t nmemb,FILE *stream); fseek() Prototype: int fseek (FILE * stream, long offset, int whence); Function allows to the new position given an index whence argument defines 12 January 2010 Knowx innovation 19
  • 25. SEEK_SET - moves the file position to the position defined by offset SEEK_CUR -moves the file position the number of bytes defined by offset from the current file position SEEK_END - moves the file position to the number of bytes defined by offset from the end of the file rewind () Resets the file read pointer back to the start of the file Prototype void rewind (FILE * stream); 12 January 2010 Knowx innovation 20
  • 26. Program #include <stdio.h> #define MAX_LINE 40 #define FILENAME "myfile.txt“ typedef struct { int id; float x_coord; float y_coord; char name[MAX_LINE+1]; } MY_TYPE_T; MY_TYPE_T object; int main() { int i; FILE *fin; fin = fopen( FILENAME, "r" ); /* Open the input file */ 12 January 2010 Knowx innovation 21
  • 27. if (fin == (FILE *)0) exit(-1); fseek( fin, (2 * sizeof(MY_TYPE_T)), SEEK_SET ); /* Get the last entry */ fread( &object, sizeof(MY_TYPE_T), 1, fin ); printf("%d %f %f %s", object.id, object.x_coord, object.y_coord, object.name ); rewind( fin ); /* Get the second to last entry */ fseek( fin, (1 * sizeof(MY_TYPE_T)), SEEK_SET ); fread( &object, sizeof(MY_TYPE_T), 1, fin ); printf("%d %f %f %s", object.id, object.x_coord, object.y_coord, object.name ); 12 January 2010 Knowx innovation 22
  • 28. /* Get the first entry */ rewind( fin ); fread( &object, sizeof(MY_TYPE_T), 1, fin ); printf("%d %f %f %s", object.id, object.x_coord, object.y_coord, object.name ); fclose( fin ); return 0; } 12 January 2010 Knowx innovation 23
  • 29. getpid() - to get the current process ID. getppid() - to get the parent process ID. getuid() - to get the user ID. getgid() - to get the group ID. 12 January 2010 Knowx innovation 24
  • 30. Program #include <stdio.h> #include <unistd.h> #include <sys/types.h> int main() { pid_t myPid; pid_t myParentPid; gid_t myGid; uid_t myUid; myPid = getpid(); myParentPid = getppid(); myGid = getgid(); 12 January 2010 Knowx innovation 25
  • 31. myUid = getuid(); printf( "my process id is %d", myPid ); printf( "my parent's process id is %d", myParentPid ); printf( "my group id is %d", myGid ); printf( "my user id is %d", myUid ); return 0; } Output my process id is 10932. my parents process id is 10795 My group id is 500 My user id is 500 12 January 2010 Knowx innovation 26
  • 32. Process api Fork Create a new child process Wait Suspend execution until a child processes exits Signal Install a new signal handler Exec Replace the current process image with a new process image 12 January 2010 Knowx innovation 27
  • 33. Fork Creating new processes with in a given process. return value of fork is greater than zero then in the parent context. Equal to zero then in the child context. less than zero then error occurred. 12 January 2010 Knowx innovation 28
  • 34. Example pid_t pid; pid = fork(); if(pid>0) {/*parent context*/} else if (pid ==0) {/*child context*/} else {/*error occurred no child created*/} 12 January 2010 Knowx innovation 29
  • 35. 12 January 2010 Knowx innovation 30
  • 36. Program #include <sys/types.h> #include <sys/wait.h> #include <unistd.h> #include <stdio.h> #include <errno.h> int main() { pid_t ret; int status, I, role = -1; 12 January 2010 Knowx innovation 31
  • 37. ret = fork(); if (ret > 0) { printf("Parent: This is the parent process (pid %d)", getpid()); for (i = 0 ; i < 6 ; i++) { printf("Parent: At count %d", i); sleep(1); } ret = wait( &status ); role = 0; } else if (ret == 0) { printf("Child: This is the child process (pid %d)", getpid()); 12 January 2010 Knowx innovation 32
  • 38. for (i = 0 ; i < 6 ; i++) { printf("Child: At count %d", i); sleep(1); } role = 1; } else { printf("Parent: Error trying to fork() (%d)", errno); } printf("%s: Exiting...", ((role == 0) ? "Parent" : "Child")); return 0; } 12 January 2010 Knowx innovation 33
  • 39. wait Suspend the calling process until a child process(created by this process) exits or until a signal is delivered. Prototype pid_t wait (int *status); 12 January 2010 Knowx innovation 34
  • 40. Signal Install a signal handler for a process. Prototype sighandler_t signal (int signum, sighandler_t handler); SIGHUP - hang up –commonly used to restart a task. SIGKILL - kill signal SIGINT - interrupt from the keyboard SIGSTOP – stop process SIGQUIT – quit signal from keyboard 12 January 2010 Knowx innovation 35
  • 41. Program #include <stdio.h> #include <sys/types.h> #include <sys/wait.h> #include <unistd.h> #include <signal.h> #include <errno.h> void usr1_handler( int sig_num ) { printf( "Process (%d) got the SIGUSR1", getpid() ); } int main() { pid_t ret; int status role = -1; signal( SIGUSR1, usr1_handler ); 12 January 2010 Knowx innovation 36
  • 42. ret = fork(); if (ret > 0) { /* Parent Context */ printf( "Parent: This is the parent process (pid %d)", getpid() ); role = 0; pause(); printf( "Parent: Awaiting child exit" ); ret = wait( &status ); } 12 January 2010 Knowx innovation 37
  • 43. else if (ret == 0) { /* Child Context */ printf( "Child: This is the child process (pid %d)", getpid() ); role = 1; pause(); } else { /* Parent Context -- Error */ printf( "Parent: Error trying to fork() (%d)", errno ); } printf( "%s: Exiting...", ((role == 0) ? "Parent" : "Child") ); return 0; } 12 January 2010 Knowx innovation 38
  • 44. exec Replaces the current process image altogether. Once the exec function replaces the current process, its pid is the same as the creating process Permits the current process context to be replace with the program specifies as the first argument. 12 January 2010 Knowx innovation 39
  • 45. Example execl(“/bin/ls”,”ls”,”-la”,null); This command replaces the current process with the ls (list directory) Prototypes for the variants of exec int execl (const char *path,const char * arg, …,..) int execlp(const char *path,const char *arg,……) int execv(const char *path, char *const argv[]) int execvp(const char *file, char *const argv[]) 12 January 2010 Knowx innovation 40
  • 46. Program for shell interpreter #include <sys/types.h> #include <sys/wait.h> #include <unistd.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #define MAX_LINE 80 int main() { int status; pid_t childpid; char cmd[MAX_LINE+1]; char *sret; 12 January 2010 Knowx innovation 41
  • 47. while (1) { printf("mysh>"); sret = fgets( cmd, sizeof(cmd), stdin ); if (sret == NULL) exit(-1); cmd[ strlen(cmd)-1] = 0; if (!strncmp(cmd, "bye", 3)) exit(0); childpid = fork(); if (childpid == 0) { execlp( cmd, cmd, 0 ); } else if (childpid > 0) { waitpid( childpid, &status, 0 ); } printf(""); } return 0; } 12 January 2010 Knowx innovation 42
  • 48. Message queues Messages are small collections of data (400 bytes, for example) that can be passed between cooperating programs through a message queue. Messages within a queue can be of different types, and any process with proper permissions can receive the messages. 12 January 2010 Knowx innovation 43
  • 49.
  • 50. Program #include <stdio.h> #include <sys/msg.h> #define MY_MQ_ID 111 int main() { int msgid; /* Create the message queue with the id MY_MQ_ID */ msgid = msgget( MY_MQ_ID, 0666 | IPC_CREAT ); if (msgid >= 0) { printf( "Created a Message Queue %d", msgid ); } return 0; } 12 January 2010 Knowx innovation 45
  • 51.
  • 52. MSGSZ is the length of the message sent in bytes. MSGFLG specifies the action to be taken if one or more of the following are true. The number of bytes already in the queue is equal to msg_qbytes. The total number of messages on all queues on the system has reached a maximum limit Action to be taken If (msgflg & IPC_NOWAIT) is non-zero, the message will not be sent and the calling process will return immediately If (msgflg & IPC_NOWAIT) is 0, the calling process will suspend execution until one of the following occurs: 12 January 2010 Knowx innovation 47
  • 53. Program #include <sys/types.h> #include <sys/ipc.h> #include <sys/msg.h> #include <stdio.h> #include <string.h> #define MSGSZ 128 typedef struct msgbuf /* will hold the message to be put in the queue */ { long mtype; /* priority of message */ char mtext[MSGSZ]; /* the message that is stored */ } message_buf; main() { int msqid; int msgflg = IPC_CREAT | 0666; key_t key; message_buf sbuf; size_t buf_length; key = 10; printf("Calling msgget with key %#lx and flag %#o",key,msgflg); 12 January 2010 Knowx innovation 48
  • 54. /*A queue is created using the msget function with a key value 10 and the flag parameter being IPC_CREAT|06668 */ if ((msqid = msgget(key, msgflg )) < 0) { perror("msgget"); exit(1); } else printf("msgget: msgget succeeded: msqid = %d", msqid); sbuf.mtype = 1; /*setting the priority as 1 */ printf("msgget: msgget succeeded: msqid = %d", msqid); (void) strcpy(sbuf.mtext, "I am in the queue?"); /* copy the text "I am in the queue" into the array mtext which is message array */ printf("msgget: msgget succeeded: msqid = %d", msqid); 12 January 2010 Knowx innovation 49
  • 55. buf_length = strlen(sbuf.mtext) + 1 ; /*sending the message with option IPC_NOWAIT */ if (msgsnd(msqid, &sbuf, buf_length, IPC_NOWAIT) < 0) { printf ("%d, %d, %s, %d", msqid, sbuf.mtype, sbuf.mtext, buf_length); perror("msgsnd"); exit(1); } else printf("Message: amp;quot;%samp;quot; Sent", sbuf.mtext); exit(0); } 12 January 2010 Knowx innovation 50
  • 56.
  • 57. program #include <sys/types.h> #include <sys/ipc.h> #include <sys/msg.h> #include <stdio.h> #define MSGSZ 128 typedef struct msgbuf /* structure that will hold the message obtained from the queue*/ { long mtype; /*priority of message */ char mtext[MSGSZ]; /*message that stored */ } message_buf; main() { 12 January 2010 Knowx innovation 52
  • 58. int msqid; key_t key; message_buf rbuf; key = 10; /*creating a queue with the key value 10, */ if ((msqid = msgget(key, 0666)) < 0) { perror("msgget"); exit(1); } /*acquires the message from the queue into rbuf*/ if (msgrcv(msqid, &rbuf, MSGSZ, 1, 0) < 0) { perror("msgrcv"); exit(1); } printf("%s", rbuf.mtext); exit(0); } 12 January 2010 Knowx innovation 53
  • 59.
  • 60. 12 January 2010 Knowx innovation 55
  • 61. Variable that is protected. It provides a means to restrict access to a resource that is shared amongst two or more processes Two operations are permitted , called acquire and release. 2 types of semaphore. Binary and Counting 12 January 2010 Knowx innovation 56 Semaphore
  • 62. The signal notations P(semaphore variable) for wait V(semaphore variable) for signal 12 January 2010 Knowx innovation 57
  • 63. A binary semaphore is a variable that can take only the values 0 and 1. Represents a single resource and therefore when one process has acquired it,others are blocked until it is released. P(sv) if sv greater than 0 , decrement sv.ifsvis zero suspend execution of the process V(sv) if other process has been suspended waiting for sv, make it resume.if no waiting, increment sv 12 January 2010 Knowx innovation 58 Binary semaphore
  • 64. 12 January 2010 Knowx innovation 59
  • 65. Represent shared resources in quantities greater than one. It could represent the entire set of buffers by setting its value to the number of buffers available. Whenever the process acquires the semaphore, the value decrement . When the semaphore value reaches zero, process are blocked until it becomes a non zero. 12 January 2010 Knowx innovation 60 Counting semaphore
  • 66. 12 January 2010 Knowx innovation 61
  • 67.
  • 68. sem_id, is the semaphore identifier, as returned from semget. sem_ops, is a pointer to an array of structures, each of which will have at least the following members: Struct sembuf {short sem_num; short sem_op; short sem_flg; } 12 January 2010 Knowx innovation 63
  • 69. Program to acquire the semaphore. #define MY_SEM_ID 111 #define MY_SEMARRAY_ID 112 #define NUM_SEMAPHORES 10 #include <stdio.h> #include <sys/sem.h> #include <stdlib.h> #include "common.h" int main() { int semid; struct sembufsb; /* Get the semaphore with the id MY_SEM_ID */ semid = semget( MY_SEM_ID, 1, 0 ); 12 January 2010 Knowx innovation 64
  • 70. if (semid >= 0) { sb.sem_num = 0; sb.sem_op= -1; sb.sem_flg= 0; printf( "semacq: Attempting to acquire semaphore %d", semid ); /* Acquire the semaphore */ if (semop( semid, &sb, 1 ) == -1) { printf("semacq: semop failed."); exit(-1); } printf( "semacq: Semaphore acquired %d", semid); } return 0; } 12 January 2010 Knowx innovation 65
  • 71. Program to release the semaphore. #define MY_SEM_ID 111 #define MY_SEMARRAY_ID 112 #define NUM_SEMAPHORES 10 #include <stdio.h> #include <sys/sem.h> #include <stdlib.h> #include "common.h" int main() { int semid; struct sembufsb; /* Get the semaphore with the id MY_SEM_ID */ semid = semget( MY_SEM_ID, 1, 0 ); 12 January 2010 Knowx innovation 66
  • 72. if (semid >= 0) { printf( "semrel: Releasing semaphore %d", semid); sb.sem_num = 0; sb.sem_op= 1; sb.sem_flg= 0; /* Release the semaphore */ if (semop( semid, &sb, 1 ) == -1) { printf("semrel: semop failed."); exit(-1); } printf( "semrel: Semaphore released %d", semid ); } return 0; } 12 January 2010 Knowx innovation 67
  • 73. 12 January 2010 Knowx innovation 68