Advance C

Last Updated :
Discuss
Comments

Question 1

Which of these is a system call?

  • printf()

  • fork()

  • scanf()

  • strcpy()

Question 2

What will be the output of the following code?

C++
#include <unistd.h>
#include <stdio.h>

int main() {
    pid_t pid = fork();
    if (pid == 0)
        printf("Child\n");
    else
        printf("Parent\n");
    return 0;
}
  • Only Parent

  • Only Child

  • Child then Parent (order not guaranteed)

  • Compiler error

Question 3

The fork() system call returns ____ in the child process.

  • 0

  • -1

  • child PID

  • parent PID

Question 4

Which system call is used to replace the current process image with a new one?

  • fork()

  • exec()

  • exit()

  • wait()

Question 5

Which header file is required for pthreads in C?

  • <thread.h>

  • <pthread.h>

  • <threads.h>

  • <multithread.h>

Question 6

pthread_create returns ____ on success.

  • 0

  • -1

  • NULL

  • thread ID

Question 7

Which of these is used to wait for a thread to terminate?

  • pthread_exit()

  • pthread_join()

  • pthread_yield()

  • pthread_wait()

Question 8

Which function is used to create a message queue?

  • mq_open()

  • msgget()

  • semget()

  • shmget()

Question 9

What is printed if successful?

C
#include <sys/ipc.h>
#include <sys/msg.h>
#include <stdio.h>

int main() {
    int id = msgget(IPC_PRIVATE, 0666 | IPC_CREAT);
    if (id < 0) printf("Error\n");
    else printf("Queue created\n");
    return 0;
}


  • Queue created

  • Error

  • Nothing

  • Compiler error

Question 10

Which of these is NOT an IPC mechanism?

  • Message queues

  • Semaphores

  • Shared memory

  • Signals

There are 10 questions to complete.

Take a part in the ongoing discussion