CECS 325 Midterm Review Exam (REAL) | With Verified Answers What is the first thing you need to do in order to use pthread? #include How would you compile a C++ program with multithreading capabilities in the Linux T
...
CECS 325 Midterm Review Exam (REAL) | With Verified Answers What is the first thing you need to do in order to use pthread? #include
How would you compile a C++ program with multithreading capabilities in the Linux Terminal? c++ program.cpp -lpthread -o program What is the first parameter in pthread_create? thread, initialized as pthread_t t1; on a previous line in order to pass information on the thread through a variable What is the 2nd parameter in pthread_create? attribute, not necessary for our class but it's a pointer to a structure that can define thread attributes such as stack address etc What should you pass through the 2nd parameter in pthread_create by default? NULL What is the 3rd parameter in pthread_create? the function in which you want to run through the thread, EX: mySort Do functions in the 3rd parameter of pthread_create include their own parameters? NO, the 4th parameter of pthread_create includes the function's parameters. What is the 4th parameter in pthread_create? arg (arglist), pointer to void that contains the arguments to the function defined in the earlier argument What is the function to terminate a thread? void pthread_exit(void *retval); What is the function to make a thread wait? pthread_join(thread1, NULL); Why is the pthread_join function usually required? We need to wait till the threads are complete, otherwise the main function will continue while the threads are processing, risking termination of the program(return 0;) before the threads are completed. How do you declare a string in C/C++? (cstring) char s[5]; can visualize it as an array with 5 element slots What should always be included at the end of a C/C++ string? (cstring) \0, or null pointer Is char a[4] = ('a', 'b', 'c', 'd') valid? (cstring) no, assigning 5 characters to a string that has 4 characters. \0 is automatically initialized as the end of any given string. What is the strlen() function? takes a string as its argument and returns the string's length, excluding the \0 at the end. ''' int strlen(char n []) { int i = 0; while (n[i++] != '\0') {} return i - 1; } ''' What is the difference between pass by value and pass by reference? When passing by value, the value passed in a parameter is not changed after the function operations, whilst passing by reference the value does change. Pass by reference: myfunc(& int x){ x+= 5; } int main() { int x = 10; myfunc(x); print(x) } OUTPUT: 15 Pass by value: myfunc(int x){ x+= 5; } int main() { int x = 10; myfunc(x); print(x) } OUTPUT: 10 What is sizeof()? returns the size of either a variable, type or expression allocated in the memory in bytes. What is the function of the linux command "cd"? to change directories and change between file lists What is the function of the linux command "ls"? most commonly used command, lists all folders and files in a particular file path What is the function of the linux command "man"? also known as the manual command, man interfaces the system manual to any given command. What is the function of the linux command "cat"? short for concatenate, concatenate files and print on the standard output What is the function of the linux command "mkdir"? create a directory What is the function of the linux command "chmod"? widely used by admins, sets file permissions on a folder or file What is the function of the linux command "rmdir"? remove a file or directory from a location What is the function of the linux command "touch"? creating, changing, and modifying file timing information What is the function of the linux command "locate"? also known as find command, used to locate a particular file : locate -i final will locate files with the name final What is the function of the linux command "clear"? clears up the command prompt screen What is the function of the linux command "rm"? removes a particular file what is the function of the linux command "mv"? move a file to another directory EX: mv/myfolder/appli/myapps /myfolder/newapp/firstapp what is the function of the linux command "curl"? optionally installed linux package, used to extract info from URLs or IP addresses what is the function of the linux command "echo"? prints specified text in terminal window EX: echo Hello World what is the function of the linux command "free"? displays amount of free and used memory in the system what is the function of the linux command "groups"? display a list of all groups aka groups of users what is the function of the linux command "head"? displays the first 10 lines of a given file EX: head numbers.txt what is the function of the linux command "history"? displays a list of previously used commands what is the function of the linux command "passwd"? changes password EX: sudo passwd yo what is the function of the linux command "ping"? checks network connection and troubleshooting networking issues EX: ping 8.8.8.8 what is the function of the linux command ".alias"? tells the shell to return one string with a different string while performing the commands what is the function of the linux command "ZIP"? confines and packages files EX: $zip newfile.zip name.txt what is the function of the linux command "dd"? versatile command used for converting and copying files what is the function of the linux command "chown"? enables users to modify the user and/or group control of an assigned file, directory, or representative link what is the function of the linux command "sudo"? "Super User DO" command, very important, prefix applied to any command that only superusers can execute. lets users operate applications as a different user, by default the root what is the function of the linux command "cal"? displays the current calendar date, can be display different days, entire calendar, julian date etc with various commands what is the function of the linux command "chage"? used by admins to change the expiry data of a user password what is the function of the linux command "df"? retrieves file system data what is the function of the linux command "bc"? command line calculator what is the function of the linux command "uname"? unfolds system data, like operating system, version, processor etc. struct student { string name; int age; char grade; }; student s1, *sptr; sptr = &s1; s1.name = "Dakota"; what code would you use to set Dakota's age to 23? sptr->age = 23; What does Amdahl's Law describe? sequential work will limit speedup due to parallelism Is a separate header file to a cpp required? no, although its handy for larger classes int nums[6] = {2, 4, 6, 8, 10, 12}; printArray(nums); void printArray(int n[ ]) { for(int i=0, i
[Show More]