61.
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;
}

62.
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;
}

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

69.
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

Read More Section(Linux)

Each Section contains maximum 100 MCQs question on Linux. To get more questions visit other sections.