├── README.md ├── chardev ├── Makefile ├── ebbchar.c ├── ebbchar.ko ├── ebbchar.mod.c ├── ebbchar.mod.o ├── ebbchar.o ├── modules.order └── testebbchar.c ├── example-1.sh ├── example-2.sh ├── example-3.sh ├── example-4.sh ├── example-5.sh ├── example-6.sh ├── example-7.sh ├── example-8.sh ├── kernel-programming ├── Makefile ├── README.md ├── helloworld.c ├── message.c ├── message.ko ├── message.mod.c ├── message.mod.o ├── message.o ├── modules.order └── simple.c ├── penguin.sh ├── system-calls ├── README.md ├── example-1-b-ls.c ├── example-1-c-mv.c ├── example-1-f-cp.c ├── example-3.c ├── example-4.c └── example-7.c ├── test ├── test1.txt ├── test2.txt └── weight.sh /README.md: -------------------------------------------------------------------------------- 1 | # INTRODUCTION TO SHELL PROGRAMMING 2 | 3 | 4 | ### To run shell script open terminal (Ctrl + Alt + T) and run 5 | 6 | ```sh 7 | bash name_of_script.sh 8 | ``` 9 | 10 | -------------------------------------------------------------------------------- /chardev/Makefile: -------------------------------------------------------------------------------- 1 | obj-m+=ebbchar.o 2 | 3 | all: 4 | make -C /lib/modules/$(shell uname -r)/build/ M=$(PWD) modules 5 | $(CC) testebbchar.c -o test 6 | clean: 7 | make -C /lib/modules/$(shell uname -r)/build/ M=$(PWD) clean 8 | rm test -------------------------------------------------------------------------------- /chardev/ebbchar.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file ebbchar.c 3 | * @author Derek Molloy 4 | * @date 7 April 2015 5 | * @version 0.1 6 | * @brief An introductory character driver to support the second article of my series on 7 | * Linux loadable kernel module (LKM) development. This module maps to /dev/ebbchar and 8 | * comes with a helper C program that can be run in Linux user space to communicate with 9 | * this the LKM. 10 | * @see http://www.derekmolloy.ie/ for a full description and follow-up descriptions. 11 | */ 12 | 13 | #include // Macros used to mark up functions e.g. __init __exit 14 | #include // Core header for loading LKMs into the kernel 15 | #include // Header to support the kernel Driver Model 16 | #include // Contains types, macros, functions for the kernel 17 | #include // Header for the Linux file system support 18 | #include // Required for the copy to user function 19 | #define DEVICE_NAME "ebbchar" ///< The device will appear at /dev/ebbchar using this value 20 | #define CLASS_NAME "ebb" ///< The device class -- this is a character device driver 21 | 22 | MODULE_LICENSE("GPL"); ///< The license type -- this affects available functionality 23 | MODULE_AUTHOR("Derek Molloy"); ///< The author -- visible when you use modinfo 24 | MODULE_DESCRIPTION("A simple Linux char driver for the BBB"); ///< The description -- see modinfo 25 | MODULE_VERSION("0.1"); ///< A version number to inform users 26 | 27 | static int majorNumber; ///< Stores the device number -- determined automatically 28 | static char message[256] = {0}; ///< Memory for the string that is passed from userspace 29 | static short size_of_message; ///< Used to remember the size of the string stored 30 | static int numberOpens = 0; ///< Counts the number of times the device is opened 31 | static struct class* ebbcharClass = NULL; ///< The device-driver class struct pointer 32 | static struct device* ebbcharDevice = NULL; ///< The device-driver device struct pointer 33 | 34 | // The prototype functions for the character driver -- must come before the struct definition 35 | static int dev_open(struct inode *, struct file *); 36 | static int dev_release(struct inode *, struct file *); 37 | static ssize_t dev_read(struct file *, char *, size_t, loff_t *); 38 | static ssize_t dev_write(struct file *, const char *, size_t, loff_t *); 39 | 40 | /** @brief Devices are represented as file structure in the kernel. The file_operations structure from 41 | * /linux/fs.h lists the callback functions that you wish to associated with your file operations 42 | * using a C99 syntax structure. char devices usually implement open, read, write and release calls 43 | */ 44 | static struct file_operations fops = 45 | { 46 | .open = dev_open, 47 | .read = dev_read, 48 | .write = dev_write, 49 | .release = dev_release, 50 | }; 51 | 52 | /** @brief The LKM initialization function 53 | * The static keyword restricts the visibility of the function to within this C file. The __init 54 | * macro means that for a built-in driver (not a LKM) the function is only used at initialization 55 | * time and that it can be discarded and its memory freed up after that point. 56 | * @return returns 0 if successful 57 | */ 58 | static int __init ebbchar_init(void){ 59 | printk(KERN_INFO "EBBChar: Initializing the EBBChar LKM\n"); 60 | 61 | // Try to dynamically allocate a major number for the device -- more difficult but worth it 62 | majorNumber = register_chrdev(0, DEVICE_NAME, &fops); 63 | if (majorNumber<0){ 64 | printk(KERN_ALERT "EBBChar failed to register a major number\n"); 65 | return majorNumber; 66 | } 67 | printk(KERN_INFO "EBBChar: registered correctly with major number %d\n", majorNumber); 68 | 69 | // Register the device class 70 | ebbcharClass = class_create(THIS_MODULE, CLASS_NAME); 71 | if (IS_ERR(ebbcharClass)){ // Check for error and clean up if there is 72 | unregister_chrdev(majorNumber, DEVICE_NAME); 73 | printk(KERN_ALERT "Failed to register device class\n"); 74 | return PTR_ERR(ebbcharClass); // Correct way to return an error on a pointer 75 | } 76 | printk(KERN_INFO "EBBChar: device class registered correctly\n"); 77 | 78 | // Register the device driver 79 | ebbcharDevice = device_create(ebbcharClass, NULL, MKDEV(majorNumber, 0), NULL, DEVICE_NAME); 80 | if (IS_ERR(ebbcharDevice)){ // Clean up if there is an error 81 | class_destroy(ebbcharClass); // Repeated code but the alternative is goto statements 82 | unregister_chrdev(majorNumber, DEVICE_NAME); 83 | printk(KERN_ALERT "Failed to create the device\n"); 84 | return PTR_ERR(ebbcharDevice); 85 | } 86 | printk(KERN_INFO "EBBChar: device class created correctly\n"); // Made it! device was initialized 87 | return 0; 88 | } 89 | 90 | /** @brief The LKM cleanup function 91 | * Similar to the initialization function, it is static. The __exit macro notifies that if this 92 | * code is used for a built-in driver (not a LKM) that this function is not required. 93 | */ 94 | static void __exit ebbchar_exit(void){ 95 | device_destroy(ebbcharClass, MKDEV(majorNumber, 0)); // remove the device 96 | class_unregister(ebbcharClass); // unregister the device class 97 | class_destroy(ebbcharClass); // remove the device class 98 | unregister_chrdev(majorNumber, DEVICE_NAME); // unregister the major number 99 | printk(KERN_INFO "EBBChar: Goodbye from the LKM!\n"); 100 | } 101 | 102 | /** @brief The device open function that is called each time the device is opened 103 | * This will only increment the numberOpens counter in this case. 104 | * @param inodep A pointer to an inode object (defined in linux/fs.h) 105 | * @param filep A pointer to a file object (defined in linux/fs.h) 106 | */ 107 | static int dev_open(struct inode *inodep, struct file *filep){ 108 | numberOpens++; 109 | printk(KERN_INFO "EBBChar: Device has been opened %d time(s)\n", numberOpens); 110 | return 0; 111 | } 112 | 113 | /** @brief This function is called whenever device is being read from user space i.e. data is 114 | * being sent from the device to the user. In this case is uses the copy_to_user() function to 115 | * send the buffer string to the user and captures any errors. 116 | * @param filep A pointer to a file object (defined in linux/fs.h) 117 | * @param buffer The pointer to the buffer to which this function writes the data 118 | * @param len The length of the b 119 | * @param offset The offset if required 120 | */ 121 | static ssize_t dev_read(struct file *filep, char *buffer, size_t len, loff_t *offset){ 122 | int error_count = 0; 123 | // copy_to_user has the format ( * to, *from, size) and returns 0 on success 124 | error_count = copy_to_user(buffer, message, size_of_message); 125 | 126 | if (error_count==0){ // if true then have success 127 | printk(KERN_INFO "EBBChar: Sent %d characters to the user\n", size_of_message); 128 | return (size_of_message=0); // clear the position to the start and return 0 129 | } 130 | else { 131 | printk(KERN_INFO "EBBChar: Failed to send %d characters to the user\n", error_count); 132 | return -EFAULT; // Failed -- return a bad address message (i.e. -14) 133 | } 134 | } 135 | 136 | /** @brief This function is called whenever the device is being written to from user space i.e. 137 | * data is sent to the device from the user. The data is copied to the message[] array in this 138 | * LKM using the sprintf() function along with the length of the string. 139 | * @param filep A pointer to a file object 140 | * @param buffer The buffer to that contains the string to write to the device 141 | * @param len The length of the array of data that is being passed in the const char buffer 142 | * @param offset The offset if required 143 | */ 144 | static ssize_t dev_write(struct file *filep, const char *buffer, size_t len, loff_t *offset){ 145 | sprintf(message, "%s(%zu letters)", buffer, len); // appending received string with its length 146 | size_of_message = strlen(message); // store the length of the stored message 147 | printk(KERN_INFO "EBBChar: Received %zu characters from the user\n", len); 148 | return len; 149 | } 150 | 151 | /** @brief The device release function that is called whenever the device is closed/released by 152 | * the userspace program 153 | * @param inodep A pointer to an inode object (defined in linux/fs.h) 154 | * @param filep A pointer to a file object (defined in linux/fs.h) 155 | */ 156 | static int dev_release(struct inode *inodep, struct file *filep){ 157 | printk(KERN_INFO "EBBChar: Device successfully closed\n"); 158 | return 0; 159 | } 160 | 161 | /** @brief A module must use the module_init() module_exit() macros from linux/init.h, which 162 | * identify the initialization function at insertion time and the cleanup function (as 163 | * listed above) 164 | */ 165 | module_init(ebbchar_init); 166 | module_exit(ebbchar_exit); -------------------------------------------------------------------------------- /chardev/ebbchar.ko: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MainakRepositor/OS-Programs/f0998df888992aadcbdbafcd4a51a189191d674b/chardev/ebbchar.ko -------------------------------------------------------------------------------- /chardev/ebbchar.mod.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | MODULE_INFO(vermagic, VERMAGIC_STRING); 6 | 7 | __visible struct module __this_module 8 | __attribute__((section(".gnu.linkonce.this_module"))) = { 9 | .name = KBUILD_MODNAME, 10 | .init = init_module, 11 | #ifdef CONFIG_MODULE_UNLOAD 12 | .exit = cleanup_module, 13 | #endif 14 | .arch = MODULE_ARCH_INIT, 15 | }; 16 | 17 | static const struct modversion_info ____versions[] 18 | __used 19 | __attribute__((section("__versions"))) = { 20 | { 0x1e94b2a0, __VMLINUX_SYMBOL_STR(module_layout) }, 21 | { 0xfc2407d6, __VMLINUX_SYMBOL_STR(class_unregister) }, 22 | { 0xd9ce3a46, __VMLINUX_SYMBOL_STR(device_destroy) }, 23 | { 0xe249a357, __VMLINUX_SYMBOL_STR(class_destroy) }, 24 | { 0xcb3ba128, __VMLINUX_SYMBOL_STR(device_create) }, 25 | { 0x6bc3fbc0, __VMLINUX_SYMBOL_STR(__unregister_chrdev) }, 26 | { 0x82eaadde, __VMLINUX_SYMBOL_STR(__class_create) }, 27 | { 0x8133032b, __VMLINUX_SYMBOL_STR(__register_chrdev) }, 28 | { 0x4f8b5ddb, __VMLINUX_SYMBOL_STR(_copy_to_user) }, 29 | { 0x91715312, __VMLINUX_SYMBOL_STR(sprintf) }, 30 | { 0x27e1a049, __VMLINUX_SYMBOL_STR(printk) }, 31 | { 0xbdfb6dbb, __VMLINUX_SYMBOL_STR(__fentry__) }, 32 | }; 33 | 34 | static const char __module_depends[] 35 | __used 36 | __attribute__((section(".modinfo"))) = 37 | "depends="; 38 | 39 | 40 | MODULE_INFO(srcversion, "96D5965B8EFB4C23BB4D5C2"); 41 | -------------------------------------------------------------------------------- /chardev/ebbchar.mod.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MainakRepositor/OS-Programs/f0998df888992aadcbdbafcd4a51a189191d674b/chardev/ebbchar.mod.o -------------------------------------------------------------------------------- /chardev/ebbchar.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MainakRepositor/OS-Programs/f0998df888992aadcbdbafcd4a51a189191d674b/chardev/ebbchar.o -------------------------------------------------------------------------------- /chardev/modules.order: -------------------------------------------------------------------------------- 1 | kernel//home/plab-14/Desktop/1209020/chardev/ebbchar.ko 2 | -------------------------------------------------------------------------------- /chardev/testebbchar.c: -------------------------------------------------------------------------------- 1 | /** 2 | * @file testebbchar.c 3 | * @author Derek Molloy 4 | * @date 7 April 2015 5 | * @version 0.1 6 | * @brief A Linux user space program that communicates with the ebbchar.c LKM. It passes a 7 | * string to the LKM and reads the response from the LKM. For this example to work the device 8 | * must be called /dev/ebbchar. 9 | * @see http://www.derekmolloy.ie/ for a full description and follow-up descriptions. 10 | */ 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | #include 17 | 18 | #define BUFFER_LENGTH 256 ///< The buffer length (crude but fine) 19 | static char receive[BUFFER_LENGTH]; ///< The receive buffer from the LKM 20 | 21 | int main(){ 22 | int ret, fd; 23 | char stringToSend[BUFFER_LENGTH]; 24 | printf("Starting device test code example...\n"); 25 | fd = open("/dev/ebbchar", O_RDWR); // Open the device with read/write access 26 | if (fd < 0){ 27 | perror("Failed to open the device..."); 28 | return errno; 29 | } 30 | printf("Type in a short string to send to the kernel module:\n"); 31 | scanf("%[^\n]%*c", stringToSend); // Read in a string (with spaces) 32 | printf("Writing message to the device [%s].\n", stringToSend); 33 | ret = write(fd, stringToSend, strlen(stringToSend)); // Send the string to the LKM 34 | if (ret < 0){ 35 | perror("Failed to write the message to the device."); 36 | return errno; 37 | } 38 | 39 | printf("Press ENTER to read back from the device...\n"); 40 | getchar(); 41 | 42 | printf("Reading from the device...\n"); 43 | ret = read(fd, receive, BUFFER_LENGTH); // Read the response from the LKM 44 | if (ret < 0){ 45 | perror("Failed to read the message from the device."); 46 | return errno; 47 | } 48 | printf("The received message is: [%s]\n", receive); 49 | printf("End of the program\n"); 50 | return 0; 51 | } -------------------------------------------------------------------------------- /example-1.sh: -------------------------------------------------------------------------------- 1 | #go to /etc/profile.d directory and write the file named with like as welcome.sh 2 | 3 | #welcome.sh 4 | #echo "Welcome $USER" 5 | 6 | #now open terminal with root user with "sudo -i" command 7 | 8 | #and show the welcome message now 9 | 10 | echo "Welcome $USER" > /etc/profile.d/welcome.sh 11 | -------------------------------------------------------------------------------- /example-2.sh: -------------------------------------------------------------------------------- 1 | # 2.Write a script called whichdaemon.sh that checks if the httpd and init daemons are 2 | # running on your system. If an httpd is running, the script should print a message like, "This 3 | # machine is running a web server." Use ps to check on processes. 4 | 5 | ##### chekc list #### 6 | # ps 7 | # grep 8 | # wc 9 | ##################### 10 | 11 | #!/bin/bash 12 | service=init 13 | 14 | if (( $(ps -ef | grep -v grep | grep $service | wc -l) > 0 )); then 15 | echo "$service is running!" 16 | else 17 | echo "service is not running!" 18 | fi 19 | 20 | service=httpd 21 | 22 | if(( $(ps -ef | grep -v grep | grep $service | wc -l) > 0)); then 23 | echo "$service is running." 24 | else 25 | echo "$service is not running." 26 | fi 27 | -------------------------------------------------------------------------------- /example-3.sh: -------------------------------------------------------------------------------- 1 | # chekc list 2 | # ifconfig # to see ip address. 3 | # ssh 4 | # scp 5 | # ssh host-name@host-ip-address 6 | # scp -r source-directory destination-pc-name@destination-pc-ip:/home/host-name/some-directory 7 | 8 | 9 | sudo ssh plab-16@192.168.1.116 # login to remote pc 10 | # copy file to remote pc 11 | sudo scp -r /home/plab-16/Desktop/ plab-17@192.168.1.117:/home/plab-17/Desktop/ 12 | -------------------------------------------------------------------------------- /example-4.sh: -------------------------------------------------------------------------------- 1 | # 4.Create a script that will take a (recursive) copy of files in /etc so that a beginning system 2 | # administrator can edit files without fear. 3 | 4 | ### Check list #### 5 | # chmod 6 | # cp 7 | ################## 8 | 9 | 10 | sudo chmod -R a+rwx *.txt 11 | sudo cp -rv *.txt /etc/ 12 | -------------------------------------------------------------------------------- /example-5.sh: -------------------------------------------------------------------------------- 1 | # 5.Write a script that takes exactly one argument, a directory name. If the number of 2 | # arguments is more or less than one, print a usage message. If the argument is not a 3 | # directory, print another message. For the given directory, print the five biggest files and the 4 | # five files that were most recently modified. 5 | 6 | ############################ chekc list ############################################################# 7 | # du command : Estimate file space usage. 8 | # sort command : Sort lines of text files or given input data. 9 | # head command : Output the first part of files i.e. to display first 10 largest file. 10 | # find command : Search file. 11 | 12 | # du command -h option : display sizes in human readable format (e.g., 1K, 234M, 2G). 13 | # du command -s option : show only a total for each argument (summary). 14 | # du command -x option : skip directories on different file systems. 15 | # sort command -r option : reverse the result of comparisons. 16 | # sort command -h option : compare human readable numbers. This is GNU sort specific option only. 17 | # head command -10 OR -n 10 option : show the first 10 lines. 18 | ###################################################################################################### 19 | 20 | #!/bin/bash 21 | 22 | argument=$1 # $1 indicate first argument 23 | 24 | # check at list one argumetn is given 25 | if [ ! $# == 1 ]; then 26 | echo "Usage: You can send only one directory as an argument." 27 | exit 28 | fi 29 | 30 | # check the argument is an directory 31 | if [ -d "${argument}" ]; then # it's an directory. 32 | echo "Five biggest files are listed bellow" 33 | du -ah "${argument}" | sort -rh | head -n 5 34 | 35 | echo "Five files that were most recently modified are listed bellow" 36 | ls -ltr | tail -n 5 37 | else # it's not an directory. 38 | echo "Usage: your argument is not a directory." 39 | fi 40 | -------------------------------------------------------------------------------- /example-6.sh: -------------------------------------------------------------------------------- 1 | # 6.Write a script that does the following: 2 | 3 | # 1 Display the name of the script being executed. 4 | # 2 Display the first, third and tenth argument given to the script. 5 | # 3 Display the total number of arguments passed to the script. 6 | # 4 If there were more than three positional parameters, use shift to move all the 7 | # values 3 places to the left. 8 | # 5 Print all the values of the remaining arguments. 9 | # 6 Print the number of arguments. 10 | # Test with zero, one, three and over ten arguments. 11 | 12 | 13 | echo "Script name : $0" 14 | echo "First arugment is : $1" 15 | echo "Third argument is : $3" 16 | echo "Tenth arugment is : ${10}" 17 | 18 | # 3 Display the total number of arguments passed to the script. 19 | 20 | echo "Total number of program passed to this script : $#" 21 | 22 | [ "$#" -gt 3 ] && shift 3 23 | echo "After shifting parameters are $#" 24 | 25 | [ "$#" -gt 0 ] 26 | 27 | echo "The value of remaining arguments are $*" 28 | 29 | echo "number of arguemnt $#" 30 | 31 | -------------------------------------------------------------------------------- /example-7.sh: -------------------------------------------------------------------------------- 1 | # usge lsblk command to fine your usb 2 | #Replace X accordingly in both commands 3 | 4 | sudo umount /dev/sdX 5 | sudo dd if=/path/to/ubuntu.iso of=/dev/sdbX bs=1M 6 | 7 | #Just be sure /dev/sdX is the flash drive you wish to use (it will destroy the data on the flash drive). 8 | -------------------------------------------------------------------------------- /example-8.sh: -------------------------------------------------------------------------------- 1 | wget -q http://download.opensuse.org/repositories/home:/sarimkhan/xUbuntu_14.04/Release.key -O- | sudo apt-key add - 2 | 3 | sudo apt-get update 4 | 5 | sudo apt-get install ibus-avro-trusty 6 | -------------------------------------------------------------------------------- /kernel-programming/Makefile: -------------------------------------------------------------------------------- 1 | obj-m += message.o 2 | 3 | all: 4 | make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules 5 | 6 | clean: 7 | make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean 8 | -------------------------------------------------------------------------------- /kernel-programming/README.md: -------------------------------------------------------------------------------- 1 | 2 | ## How to run kernel module 3 | ### For running kernel module you need two file 4 | * Makefile 5 | * name_of_code.c file 6 | 7 | First Configure your `Makefile` according to your `.c` file. A normal `Makefile` look like bollow 8 | ```sh 9 | obj-m += name_of_your_c_program.o 10 | 11 | all: 12 | make -C /lib/modules/$(shell uname -r)/build M=$(PWD) modules 13 | 14 | clean: 15 | make -C /lib/modules/$(shell uname -r)/build M=$(PWD) clean 16 | ``` 17 | 18 | ## Compile code 19 | Go to your source code directory and run 20 | ```sh 21 | 22 | make # compile source code 23 | sudo insmod name_of_your_program.ko # insert in kernel 24 | sudo rmmod name_of_your_program.ko # delete from kernel 25 | 26 | dmesg | tail -n 3 # see the output of module 27 | ``` 28 | ## An error that can hell your life 29 | if you get `make[1]: *** No rule to make target 'programming'. Stop` error after run make command 30 | then just rename the `kernel programming` directory to `kernelprogramming` 31 | -------------------------------------------------------------------------------- /kernel-programming/helloworld.c: -------------------------------------------------------------------------------- 1 | #include /* Needed by all modules */ 2 | #include /* Needed for KERN_INFO */ 3 | 4 | int init_module(void){ 5 | printk(KERN_INFO "Hello world.\n"); 6 | 7 | 8 | 9 | return 0; 10 | } 11 | 12 | void cleanup_module(void){ 13 | printk(KERN_INFO "Goodbye world.\n"); 14 | } 15 | -------------------------------------------------------------------------------- /kernel-programming/message.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | char *mystring; 5 | module_param(mystring, charp, 0000); 6 | 7 | int init_module(void){ 8 | printk(KERN_INFO "mystring is a string: %s\n", mystring); 9 | return 0; 10 | } 11 | 12 | void cleanup_module(void){ 13 | printk(KERN_INFO "Goodbye world.\n"); 14 | } 15 | 16 | -------------------------------------------------------------------------------- /kernel-programming/message.ko: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MainakRepositor/OS-Programs/f0998df888992aadcbdbafcd4a51a189191d674b/kernel-programming/message.ko -------------------------------------------------------------------------------- /kernel-programming/message.mod.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | MODULE_INFO(vermagic, VERMAGIC_STRING); 6 | 7 | __visible struct module __this_module 8 | __attribute__((section(".gnu.linkonce.this_module"))) = { 9 | .name = KBUILD_MODNAME, 10 | .init = init_module, 11 | #ifdef CONFIG_MODULE_UNLOAD 12 | .exit = cleanup_module, 13 | #endif 14 | .arch = MODULE_ARCH_INIT, 15 | }; 16 | 17 | static const struct modversion_info ____versions[] 18 | __used 19 | __attribute__((section("__versions"))) = { 20 | { 0x1e94b2a0, __VMLINUX_SYMBOL_STR(module_layout) }, 21 | { 0x62a79a6c, __VMLINUX_SYMBOL_STR(param_ops_charp) }, 22 | { 0x27e1a049, __VMLINUX_SYMBOL_STR(printk) }, 23 | { 0xbdfb6dbb, __VMLINUX_SYMBOL_STR(__fentry__) }, 24 | }; 25 | 26 | static const char __module_depends[] 27 | __used 28 | __attribute__((section(".modinfo"))) = 29 | "depends="; 30 | 31 | 32 | MODULE_INFO(srcversion, "129B5A951F45E7BEBFFBBB7"); 33 | -------------------------------------------------------------------------------- /kernel-programming/message.mod.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MainakRepositor/OS-Programs/f0998df888992aadcbdbafcd4a51a189191d674b/kernel-programming/message.mod.o -------------------------------------------------------------------------------- /kernel-programming/message.o: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/MainakRepositor/OS-Programs/f0998df888992aadcbdbafcd4a51a189191d674b/kernel-programming/message.o -------------------------------------------------------------------------------- /kernel-programming/modules.order: -------------------------------------------------------------------------------- 1 | kernel//home/plab-14/Desktop/1209020/code/message.ko 2 | -------------------------------------------------------------------------------- /kernel-programming/simple.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int simple_init(void) 6 | { 7 | printk(KERN_INFO "Loading Module\n"); 8 | 9 | return 0; 10 | } 11 | 12 | void simple_exit(void) 13 | { 14 | printk(KERN_INFO "Removing Module\n"); 15 | } -------------------------------------------------------------------------------- /penguin.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # add the comment 3 | if [ "$1" == fish ]; then 4 | echo "Humm fish..." 5 | else 6 | echo "Tux don't like that" 7 | fi 8 | -------------------------------------------------------------------------------- /system-calls/README.md: -------------------------------------------------------------------------------- 1 | # Run command: 2 | ```sh 3 | gcc name_of_program.c 4 | ./a.out 5 | ``` 6 | if we need to send command line argument then run command: 7 | ```sh 8 | gcc name_of_program.c 9 | ./a.out give_the_argument_here 10 | ``` 11 | 12 | ### Exampe: 13 | ```sh 14 | gcc example-1-b-ls.c 15 | ./a.out /home/menon/Desktop/os-lab/ 16 | ``` 17 | 18 | To knowo more about gcc command open terminal and run 19 | ```sh 20 | gcc --help 21 | man gcc 22 | ``` 23 | -------------------------------------------------------------------------------- /system-calls/example-1-b-ls.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main(int argc, char **argv) 6 | { 7 | if(argc == 1) { 8 | printf("Usage: %s [directory]\n", *argv); 9 | exit(0); 10 | } 11 | struct dirent *dp; 12 | DIR *dirp = opendir(argv[1]); 13 | while ((dp = readdir(dirp)) != NULL) { 14 | puts(dp->d_name); 15 | } 16 | 17 | closedir(dirp); 18 | return 0; 19 | } 20 | -------------------------------------------------------------------------------- /system-calls/example-1-c-mv.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | int main(int argc,char *argv[] ) 7 | { 8 | int i, fd1, fd2; 9 | char *file1, *file2, buf[2]; 10 | file1 = argv[1]; 11 | file2 = argv[2]; 12 | 13 | printf("Name of file1 is = %s name of file2 is = %s\n",file1, file2); 14 | fd1 = open(file1, O_RDONLY, 0777); 15 | fd2 = creat(file2, 0777); 16 | 17 | while(i = read(fd1, buf, 1) > 0) { 18 | write(fd2, buf, 1); 19 | } 20 | 21 | remove(file1); 22 | close(fd1); 23 | close(fd2); 24 | 25 | return 0; 26 | } 27 | -------------------------------------------------------------------------------- /system-calls/example-1-f-cp.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #define BUF_SIZE 1024 5 | 6 | int main(int argc , char* argv[]) 7 | { 8 | int fp,fq; 9 | ssize_t bytesRead, bytesWritten; 10 | 11 | char buffer[BUF_SIZE]; 12 | mode_t mode = S_IRUSR | S_IWUSR | S_IXUSR | S_IRGRP |S_IROTH | S_IXOTH ; 13 | 14 | fp = open (argv [1], O_RDONLY); 15 | if(fp == -1 ) { 16 | perror("the source file can't be opened in read mode"); 17 | return 1; 18 | } 19 | fq = open (argv[2], O_WRONLY | O_EXCL | O_CREAT, mode); 20 | 21 | if(fq == -1) { 22 | perror("the source file can't be opened in write mode"); 23 | return 2; 24 | } 25 | while((bytesRead = read (fp, &buffer, BUF_SIZE)) > 0) { 26 | bytesWritten=write (fq, &buffer, (ssize_t)bytesRead); 27 | } 28 | close (fp); 29 | close (fq); 30 | 31 | return 0; 32 | } 33 | -------------------------------------------------------------------------------- /system-calls/example-3.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | int main() 7 | { 8 | int pfds[2]; 9 | char buf[30]; 10 | 11 | if(pipe(pfds) == -1) { 12 | perror("pipe failed"); 13 | exit(1); 14 | } 15 | if(!fork()) { 16 | close(1); 17 | dup(pfds[1]); 18 | system ("ls -l"); 19 | } 20 | else { 21 | printf("parent reading from pipe \n"); 22 | 23 | while(read(pfds[0], buf,80)) { 24 | printf("%s \n" ,buf); 25 | } 26 | } 27 | 28 | return 0; 29 | } 30 | -------------------------------------------------------------------------------- /system-calls/example-4.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | int main(int argc, char *argv[]) 6 | { 7 | char d[50]; 8 | 9 | if(argc == 2) { 10 | bzero(d,sizeof(d)); 11 | strcat(d,"ls "); 12 | strcat(d,"-i "); 13 | strcat(d,argv[1]); 14 | system(d); 15 | } 16 | else { 17 | printf("Invalid No. of inputs"); 18 | } 19 | return 0; 20 | } 21 | -------------------------------------------------------------------------------- /system-calls/example-7.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | 4 | int mutex = 1, full = 0, empty = 3, x = 0; 5 | 6 | int main() 7 | { 8 | int n; 9 | void producer(); 10 | void consumer(); 11 | int wait(int); 12 | int signal(int); 13 | 14 | printf("\n1.Producer\n2.Consumer\n3.Exit"); 15 | while(1) 16 | { 17 | printf("\nEnter your choice:"); 18 | scanf("%d",&n); 19 | switch(n) 20 | { 21 | case 1: if((mutex == 1) && (empty != 0)) 22 | producer(); 23 | else 24 | printf("Buffer is full!!"); 25 | break; 26 | case 2: if((mutex == 1) && (full != 0)) 27 | consumer(); 28 | else 29 | printf("Buffer is empty!!"); 30 | break; 31 | case 3: 32 | exit(0); 33 | break; 34 | } 35 | } 36 | return 0; 37 | } 38 | 39 | int wait(int s) { 40 | return (--s); 41 | } 42 | 43 | int signal(int s) { 44 | return(++s); 45 | } 46 | 47 | void producer() 48 | { 49 | mutex = wait(mutex); 50 | full = signal(full); 51 | empty = wait(empty); 52 | x++; 53 | printf("\nProducer produces the item %d",x); 54 | mutex = signal(mutex); 55 | } 56 | 57 | void consumer() 58 | { 59 | mutex = wait(mutex); 60 | full = wait(full); 61 | empty = signal(empty); 62 | printf("\nConsumer consumes item %d",x); 63 | x--; 64 | mutex = signal(mutex); 65 | } 66 | -------------------------------------------------------------------------------- /test: -------------------------------------------------------------------------------- 1 | hello world 2 | hello grep 3 | -------------------------------------------------------------------------------- /test1.txt: -------------------------------------------------------------------------------- 1 | this is test1 file cat 2 | -------------------------------------------------------------------------------- /test2.txt: -------------------------------------------------------------------------------- 1 | this is test2 file cat 2 | -------------------------------------------------------------------------------- /weight.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | # This script prints a message about your weight if you give it your 4 | # weight in kilos and height in centimeters. 5 | 6 | if [ ! $# == 2 ]; then 7 | echo "Usage: $0 weight_in_kilos length_in_centimeters" 8 | exit 9 | fi 10 | 11 | weight="$1" 12 | height="$2" 13 | idealweight=$[$height - 110] 14 | 15 | if [ $weight -le $idealweight ] ; then 16 | echo "You should eat a bit more fat." 17 | else 18 | echo "You should eat a bit more fruit." 19 | fi 20 | --------------------------------------------------------------------------------