Last Updated on May 5, 2022 by Admin 2

Processes and Threads M5 Test

  1. Which of the “C” programming language standards offers built-in thread implementation?

    • C99
    • C89
    • C11
    • ANSI C
  2. Which of the following main() function’s headers is valid?

    • int main(int argc, char *argv[], char env)
    • int main(int argc, char * argv[], char **env)
    • int main(int argc, char *argv[], char *env)
    • int main(int argc, char * argv[], char ***env)
  3. Assuming that the code was compiled and run in a Unix/Linux environment, what is its expected output?

    #include <stdio.h>
    #include <unistd.h>
    int x = 0;
    int main(void) {
        if(fork()){
                   printf("%d", ++x);
                return 0;
         }else{
                   printf("%d", ++x);
                return 0;
        }
    }
    • 12
    • 21
    • 11
    • 22
  4. To determine if the system shell is available or not, you would use the following invocation:

    • if(system("shell")) {...}
    • if(system(""){...}
    • if(system("NULL")) {...}
    • if(system(NULL)){...}
  5. A variant of the exec() function, designed to pass a copy of the environment to a new process as well as use PATH to find the executable and accepting argument placed in an array, is named:

    •  execlp
    • execl
    • execlpe
    • execvpe
  6. The WINAPI specifier means that the function:

    • is a static function
    • is not accessible from the outside
    • is an obsolete implementation of a standard Windows service
    • uses the standard MS Windows calling conversion
  7. In an MS Windows environment, if the main thread wants to wait for all the other threads to complete, it:

    • may use the WaitForMultipleObjects() function
    • must use a number of subsequent invocations of the WaitForSingleObject() function
    • uses the Sleep() function
    • spends some time in an empty delay loop
  8. What is the possible result of the following invocation?

    #include <stdlib.h>
    int main(int argc, char * argv[]){
        system(argv[0]);
        return 0;
    }
    • a compiler error
    • a stack overflow error 
    • an OS shell error
    • an infinite loop of launches
  9. The term “obtain a mutex”:

    • means the same as “lock a mutex” in different OS environments
    • is not uses in any OS environment
    • means the same as “release a mutex” in different OS environments
    • means the same as “close a mutex” in different OS environments
  10. Assuming that the following snippet is executed in an MS Windows environment, its effect is:

    putenv("VAR=");
    • to printf the VAR’s value to stdout
    • to remove the VAR from the environment 
    • nothing 
    • to set the VAR’s value to an empty string
  11. The pid_t type is:

    • an unsigned int
    • a pointer to  a void
    • an int
    • a string
  12. In the MS Windows threads, a single thread is represented as a value of type:

    • HANDLE
    • thred_t
    • thrd_t
    • msthread_t
  13. In the MS Windows threads, a single thread is represented as a value of type:

    • HANDLE
    • thred_t
    • thrd_t
    • msthread_t
  14. A thread, in the Pthread sense, is a function of type:

    • void thread(void * data);
    • int thread(void * data);
    • void * thread(void);
    • void * thread(void *data);
  15. To determine its ID, a thread running in an MS Windows environment uses:

    • its own handle
    • the GetCurrentThreadId() function
    • its own address
    • its own name
  16. After successfully invocation, the fork() function:

    • returns the child’s PID in the parent and the parent’s PID in the child 
    • return 0 in the child and the child’s PIS in the parent 
    • return 0 in both child and parent 
    • return 0 in the parent and the parent’s PID in the child
  17. The MS Windows’ HANDLE data type:

    • is a structure containing a PID
    • is a string with a process name and plays a different role than a PID
    • is the same as a Unix/Linux PID
    • is a unique resource identifier and plays a different role than a PID
  18. In an MS Windows environment, the native Unix/Linux functions named wait() and waitpid():

    • are replaced by the Wait() and WaitPid() functions
    • may be substituted by the WaitForSingleObject() function
    • are not needed due to the different processes’ serving philosophies
    • have the same name and purpose
  19. Assuming that the code was compiled and run in a Unix/Linux environment, what is its expected output?

    #include <stdio.h>
    #include <unistd.h>
    #include <sys/types.h>
    #include <sys/wait.h>
    
    int main(void) {
        printf("%d", fork() ==0);
        wait(NULL);
          return 0;
    }
    • 1 or 0
    • always 00
    • 10 ​or 01
    • always 11
  20. The third main() function parameter is:

    • a NULL -terminated array of pointer to environment variables
    • a pointer to an array containing argc pointer to environment variables
    • a pointer to the first environment variable
    • a pointer to a NULL -terminated array of pointers to environment variable