Processes and Threads M5 Test
-
Which of the “C” programming language standards offers built-in thread implementation?
- C99
- C89
- C11
- ANSI C
-
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)
-
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
-
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)){...}
-
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
-
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
-
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
- may use the
-
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
-
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
-
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
- to printf the VAR’s value to
-
The
pid_t
type is:- an unsigned
int
- a pointer to a
void
- an
int
- a string
- an unsigned
-
In the MS Windows threads, a single thread is represented as a value of type:
HANDLE
thred_t
thrd_t
msthread_t
-
In the MS Windows threads, a single thread is represented as a value of type:
HANDLE
thred_t
thrd_t
msthread_t
-
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);
-
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
-
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
-
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
-
In an MS Windows environment, the native Unix/Linux functions named
wait()
andwaitpid()
:- are replaced by the
Wait()
andWaitPid()
functions - may be substituted by the
WaitForSingleObject()
function - are not needed due to the different processes’ serving philosophies
- have the same name and purpose
- are replaced by the
-
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
or0
- always
00
10
or01
- always
11
-
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
- a
Subscribe
0 Comments
Newest