Vidyalelo
Computer Science · all questions

Linux
practice.

Practice every MCQ with options. Use Show answers when you want the correct option and solution.

996

Questions

29/50

Page

Pick an option on a question to see the right answer and solution.

What is the output of second program if we run the demo1 first and after that we run demo2 in the different terminal?
/*This is demo1.c*/
#include<stdio.h>
#include<sys/ipc.h>
#include<sys/shm.h>
#include<string.h>
 
int main()
{
    int shm_id;
    char *addr;
    struct shmid_ds ds;
    shm_id = shmget((key_t)1234,10,0666|IPC_CREAT);
    if(shm_id == -1){
        perror("shmget");
    }
    addr = (char*)shmat(shm_id,NULL,SHM_RND);
    if(addr == (char *)-1){
        perror("shmat");
    }
    strcpy(addr,"Example");
    if (shmdt(addr) != 0){
        perror("shmdt");
    }
    sleep(10);      
    if( shmctl(shm_id,IPC_RMID,0) == -1){
        perror("shmctl");
    }
    return 0;
}
/*This is demo2.c*/
#include<stdio.h>
#include<sys/ipc.h>
#include<sys/shm.h>
 
int main()
{
    int shm_id;
    char *addr;
    struct shmid_ds ds;
    shm_id = shmget((key_t)1234,10,0666|IPC_CREAT);
    if(shm_id == -1){
        perror("shmget");
    }
    addr = (char*)shmat(shm_id,NULL,SHM_RND);
    if(addr == (char *)-1){
        perror("shmat");
    }
    printf("%s\n",addr);
    if (shmdt(addr) != 0){
        perror("shmdt");
    }
    return 0;
}

Select an option to see the answer and solution.

What is the output of this program?
#include<stdio.h>
#include<stdlib.h>
 
int main()
{
    int *ptr;
    ptr = (int *)calloc(1,sizeof(int));
    if (ptr != 0)
        printf("%d\n",*ptr);
    return 0;
}

Select an option to see the answer and solution.

If any sed command does not specify any address then the command is applied to

Select an option to see the answer and solution.

Which command will you use to see the available routes?

Select an option to see the answer and solution.

Which one shows the name of the operating system?

Select an option to see the answer and solution.

Which option of the kill command sends the given signal name to the specified process?

Select an option to see the answer and solution.

Proc filesystem provides the information about

Select an option to see the answer and solution.

The command "cd /proc/10/cwd" provides the

Select an option to see the answer and solution.

What is the output of this program?
#!/bin/sh
test_function1() {
    a=5
    echo "This is the first function"
    test_function2
}
test_function2() {
    echo "This is the second function" 
    test_function3
}
test_function3() {
    echo "This is the third function"
}
test_function1
exit 0

Select an option to see the answer and solution.

"ps" command uses the file . . . . . . . . to provide the information.

Select an option to see the answer and solution.

What is the output of this program?
#include<stdio.h>
#include<pthread.h>
#include<fcntl.h>
 
int fd;
void *fun_t(void *arg);
void *fun_t(void *arg)
{       
    char buff[10];
    int count;
    count = read(fd,buff,10);        
    printf("%d\n",count);
    pthread_exit("Bye");
}
int main()
{
    pthread_t pt;
    void *res_t;
    fd = open("demo.c",O_RDONLY);        
    if(pthread_create(&pt,NULL,fun_t,NULL) != 0)
        perror("pthread_create");
    if(pthread_join(pt,&res_t) != 0)
        perror("pthread_join");
    return 0;
}

Select an option to see the answer and solution.

In sysfs.h which one of the following structure represents the directory entries?

Select an option to see the answer and solution.

How do you get help about the command "cp"?

Select an option to see the answer and solution.

Which one of the following command can list the symbols defined in a library?

Select an option to see the answer and solution.

cat < file1 >> file2 | file3

Select an option to see the answer and solution.

While debugging with GDB, arguments to the program can be specified by the arguments of . . . . . . . . command.

Select an option to see the answer and solution.

What is the output of the following program?
x = 3; y = 5; z = 10;
if [( y -eq 5 -o  $z -eq 10 )]
then
    echo $x
else
    echo $y
fi

Select an option to see the answer and solution.

Which command identifies the resource of a command?

Select an option to see the answer and solution.

File descriptor table indexes which kernel structure?

Select an option to see the answer and solution.

Below is the code
int main() 
{
     int fd1, fd2;
     struct stat buff1, buff2;
     fd1 = open(“1.txt”, O_RDWR);
     fd2 = open(“2.txt”, O_RDWR | O_APPEND);
     lseek(fd1, 10000, SEEK_SET);
     write(fd1, “abcdefghij”, 10);
     write(fd2, “abcdefghij”, 10);
     fstat(fd1, &buff1);
     fstat(fd2, &buff2);
     printf(“ %d %d”, buff1.st_size, buff2.st_size);
     return 0;
}
Before running the program, the file 1.txt and 2.txt size is 20 each. What is the output?

Select an option to see the answer and solution.