Linux Debugging Questions & Answers – Timer, User & Resource Limit System Calls

This set of Linux Debugging questions and answers focuses on Timer, User and Resource Limit System Calls.

1. This program will print the

  1.    #include<stdio.h>
  2.    #include<unistd.h>
  3.  
  4.    int main()
  5.    {
  6.        long int value;
  7.        value = sysconf(_SC_CHILD_MAX);
  8.        printf("%ld\n",value);
  9.        return 0;
  10.    }

a) maximum number of simultaneous processes per user id
b) maximum number of child processes of the current process
c) minimum number of simultaneous processes per user id
d) none of the mentioned
View Answer

Answer: a
Explanation: None.
Output:
[root@localhost sanfoundry]# gcc -o san san.c
[root@localhost sanfoundry]# ./san
1024
[root@localhost sanfoundry]#

2. This program will print the

advertisement
advertisement
  1.    #include<stdio.h>
  2.    #include<unistd.h>
  3.  
  4.    int main()
  5.    {
  6.        long int value;
  7.        value = sysconf(_SC_OPEN_MAX);
  8.        printf("%ld\n",value);
  9.        return 0;
  10.    }

a) maximum number of threads in current process
b) maximum number of files that a process can have open at a time
c) segmentation fault
d) none of the mentioned
View Answer

Answer: a
Explanation: None.
Output:
[root@localhost sanfoundry]# gcc -o san san.c
[root@localhost sanfoundry]# ./san
1024
[root@localhost sanfoundry]#
Note: Join free Sanfoundry classes at Telegram or Youtube

3. This program will print the

  1.    #include<stdio.h>
  2.    #include<unistd.h>
  3.  
  4.    int main()
  5.    {
  6.        long int value;
  7.        value = pathconf("/home/sanfoundry",_PC_NAME_MAX);
  8.        printf("%ld\n",value);
  9.        return 0;
  10.    }

a) maximum numbers of the file that can store in this directory
b) maximum length of a filename in this directory that the process is allowed to create
c) segmentation fault
d) none of the mentioned
View Answer

Answer: b
Explanation: None.
Output:
[root@localhost sanfoundry]# gcc -o san san.c
[root@localhost sanfoundry]# ./san
255
[root@localhost sanfoundry]#
advertisement

4. What is the output of this program?

advertisement
  1.    #include<stdio.h>
  2.    #include<unistd.h>
  3.    #include<fcntl.h>
  4.  
  5.    int main()
  6.    {
  7.        long int value;
  8.        int fd;
  9.        fd = open("/home/sanfoundry/san.c",O_RDONLY);
  10.        value = fpathconf(fd,_PC_LINK_MAX);
  11.        printf("%ld\n",value);
  12.        return 0;
  13.    }

a) this program will print the maximum number of links to the file “san.c”
b) this program will print nothing
c) this program will give an error
d) none of the mentioned
View Answer

Answer: a
Explanation: None.
Output:
[root@localhost sanfoundry]# gcc -o san san.c
[root@localhost sanfoundry]# ./san
65000
[root@localhost sanfoundry]#

5. This program will print the

  1.    #include<stdio.h>
  2.    #include<sys/time.h>
  3.    #include<sys/resource.h>
  4.  
  5.    int main()
  6.    {
  7.        struct rlimit limit;
  8.        getrlimit(RLIMIT_FSIZE,&limit);
  9.        printf("%lu\n",limit.rlim_cur);
  10.        printf("%lu\n",limit.rlim_max);
  11.        return 0;
  12.    }

a) soft limit of the size of the file in bytes that can be created by the process
b) hard limit of the size of the file in bytes that can be created by the process
c) soft 7 hard limit of the size of the file in bytes that can be created by the process
d) none of the mentioned
View Answer

Answer: c
Explanation: The rlim_cur member specifies the soft limit and rlim_max specifies the hard limit of the resource.
Output:
[root@localhost sanfoundry]# gcc -o san san.c
[root@localhost sanfoundry]# ./san
4294967295
4294967295
[root@localhost sanfoundry]#

6. What is the output of this program?

  1.    #include<stdio.h>
  2.    #include<sys/time.h>
  3.    #include<sys/resource.h>
  4.  
  5.    int main()
  6.    {
  7.        struct rlimit limit;
  8.        if(getrlimit(RLIMIT_NOFILE,&limit) != 0)
  9.            perror("getrlimit");
  10.        printf("%lu\n",limit.rlim_max);
  11.        return 0;
  12.    }

a) this program will print the maximum numbers of the file descriptors that can be opened by a process
b) this program will print the maximum numbers of the child processes of the current process
c) this program will give an error because RLIMIT_NOFILE does not exist
d) none of the mentioned
View Answer

Answer: a
Explanation: None.
Output:
[root@localhost sanfoundry]# gcc -o san san.c
[root@localhost sanfoundry]# ./san
4096
[root@localhost sanfoundry]#

7. The hard limit of the file descriptors that can be opened by this process will become

  1.    #include<stdio.h>
  2.    #include<sys/time.h>
  3.    #include<sys/resource.h>
  4.  
  5.    int main()
  6.    {
  7.        struct rlimit limit;
  8.        limit.rlim_cur = 10;
  9.        limit.rlim_max = 20;
  10.        if(setrlimit(RLIMIT_NOFILE,&limit) != 0)
  11.            perror("setrlimit");
  12.        if(getrlimit(RLIMIT_NOFILE,&limit) != 0)
  13.            perror("getrlimit");
  14.        printf("%lu\n",limit.rlim_cur);
  15.        printf("%lu\n",limit.rlim_max);
  16.        return 0;
  17.    }

a) 10
b) 20
c) permisssion denied
d) none of the mentioned
View Answer

Answer: b
Explanation: None.

8. What is the output of this program?

  1.    #include<stdio.h>
  2.    #include<sys/time.h>
  3.    #include<sys/resource.h>
  4.  
  5.    int main()
  6.    {
  7.        struct rlimit limit;
  8.        limit.rlim_cur = 10;
  9.        if(setrlimit(RLIMIT_NOFILE,&limit) != 0)
  10.            perror("setrlimit");
  11.        return 0;
  12.    }

a) the soft limit of the file decriptors that can be opened by this process will become 10
b) the hard limit of the file decriptors that can be opened by this process will become 10
c) permission denied
d) none of the mentioned
View Answer

Answer: c
Explanation: None.
Output:
[root@localhost sanfoundry]# gcc -o san san.c
[root@localhost sanfoundry]# ./san
setrlimit: Operation not permitted
[root@localhost sanfoundry]#

9. What is the output of this program?

  1.    #include<stdio.h>
  2.    #include<sys/time.h>
  3.    #include<sys/resource.h>
  4.  
  5.    int main()
  6.    {
  7.        struct rlimit limit;
  8.        if(getrlimit(RLIMIT_CORE,&limit) != 0)
  9.            perror("getrlimit");
  10.        printf("%lu\n",limit.rlim_max);
  11.        return 0;
  12.    }

a) maximum size of a core file that can be created by this process
b) maximum number of core files that can be created by this process
c) segmentaion fault
d) none of the mentioned
View Answer

Answer: a
Explanation: None.
Output:
[root@localhost sanfoundry]# gcc -o san san.c
[root@localhost sanfoundry]# ./san
4294967295
[root@localhost sanfoundry]#

10. What is the output of this program?

  1.     #include<stdio.h>
  2.     #include<sys/time.h>
  3.     #include<sys/resource.h>
  4.  
  5.     int main()
  6.     {
  7.         struct rlimit limit;
  8.         if(getrlimit(RLIMIT_DATA,&limit) != 0)
  9.             perror("getrlimit");
  10.         printf("%lu\n",limit.rlim_max);
  11.         return 0;
  12.     }

a) maximum size of data segment of this process in bytes
b) maximum size of total available storage for this process in bytes
c) segmentaion fault
d) none of the mentioned
View Answer

Answer: b
Explanation: None.
Output:
[root@localhost sanfoundry]# gcc -o san san.c
[root@localhost sanfoundry]# ./san
4294967295
[root@localhost sanfoundry]#

Sanfoundry Global Education & Learning Series – Linux Administration & Programming.
Here’s the list of Best Books in Linux Commands & Shell Programming.
Here’s the list of Best Books in Linux Kernel, Device-Drivers & System Programming.

To practice all questions on Linux Administration & Programming, here is complete set of 1000+ Multiple Choice Questions and Answers on Linux.

If you find a mistake in question / option / answer, kindly take a screenshot and email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.