SlideShare a Scribd company logo
1 of 8
Page 1 of 8
Semester Project
. Deamon Process .
BSCS (B) Semester 8th
Batch 2016- 2020
Course # System Programming
Submitted by Submitted to
Abu-Bakr G1F16BSCS0076 Pro. Umer Iftikhar
Zain Khalid G1F16BSCS0143
University Of Central Punjab Gujranwala Campus
Page 2 of 8
Deamon Process
A daemon process is a process which runs in background and has no controlling
terminal. A daemon (also known as background processes) is UNIX and it is
known as services and agents in windows. Since a daemon process usually has
no controlling terminal so almost no user interaction is required. Daemon
processes are used to provide services that can well be done in background without
any user interaction. Daemons are processes that are often started when the system is bootstrapped
(boot time) and terminate only when the system is shut down.
Command used to check deamon processes
ps -axj
 -a option shows the status of processes owned by others,
 -x shows processes that don't have a controlling terminal.
 -j option displays the job-related information: the
o session ID
o process group ID
o controlling terminal
o terminal process group ID.
Characteristics
 A daemon is long-lived, often created at system startup and runs until the system is shut down
 It runs in the background and has no controlling terminal. The lack of a controlling terminal
ensures that the kernel never automatically generates any terminal-related signals for a daemon
Almost all daemons have names that end with the letter "d". For example, httpd the daemon that handles
the Apache server,or, sshd which handles SSH remote access connections.
Some popular Categories of deamons are as follow
KERNEL DAEMONS
 Deamons jo kernel leve services provide kertatay hain, and cannot be manuplated by system
adminstrator jesay k example next page
For architectural reasons,a few parts of the Linux kernel are managed as if they were user processes. On
older kernels, these processes could be identified by their low PIDs and names that start with k, such as
kupdate, kswapd, keventd, and kapm. The naming is less consistent under the 2.6 kernels, but ps always
shows the names of kernel threads in square brackets. For the most part, these processes dealwith various
aspects of I/O, memory management, and synchronization of the disk cache. They cannot be manipulated
by the system administrator and should be left alone. Daemons that include an N parameter in their names
Page 3 of 8
Port numbers are not arbitrary. All machines must agree about which services go with which ports;
otherwise, requests will constantly be directed to the wrong port. If you are creating a site-specific
service, pick a high port number (greater than 1023) that is not already listed in the services file.
If you are familiar with the implementation of the kernel, it is occasionally useful to change these
processes’ execution priorities. However,this is not a standard administrative task. Daemons (as shown
by ps) run separately on each CPU of a multi-CPU system; the N tells you which copy goes with which
CPU.
Major kernel daemons
Daemon Function
 ksoftirqd/N
Handles software interrupts when the load is high
 kacpid
Deals with the ACPI subsystem
 kblockd/N
Blocks subsystem work
 aio/N
Retries asynchronous I/Os
 kswapdN
Moves pages to swap
 ata/N
Does processing for serial ATA support
 scsi_eh_N
Performs SCSI error handling
 kjournald
Supports journaling filesystems
 events/N
Does generic work queue processing
PRINTING DAEMONS
Several printing systems are in common use, and each has its own family of commands and daemons that
 provide printing-related services. In some cases,the families have been hybridized; in others
cases,multiple variants run on a single system.
cupsd:scheduler for the Common UNIX Printing System
CUPS provide a portable printing facility by implementing version 1.1 of the Internet Printing Protocol. It
allows remote users to print to their offices (or vice versa) by using a web interface. CUPS has become
quite popular and is most systems’ default printing manager. It is flexible enough to allow for remote
authentication.
lpd: manage printing
lpd is responsible for the old-style BSD print spooling system. It accepts jobs from users and forks
processes that perform the actual printing. lpd is also responsible for transferring print jobs to and
from remote systems. lpd can sometimes hang and then must be manually restarted.
Page 4 of 8
FILE SERVICE DAEMONS
The following daemons are part of the NFS(Network File System) or Samba file sharing systems. We
give only a brief description of their functions here. NFS is described in detail in Chapter 16, and Samba is
covered starting on page 828.
rpc.nfsd:serve files
rpc.nfsd runs on file servers and handles requests from NFS clients. In most NFS implementations, nfsd is
really just a part of the kernel that has been dressed up as a process for scheduling reasons. Linux actually
sports two different implementations, one of which follows this convention and one of which runs in user
space. The kernel implementation is more popular and is most distributions’ default.
rpc.nfsd accepts a single argument that specifies how many copies of itself to fork.
rpc.mountd:respond to mount requests
rpc.mountd accepts filesystem mount requests from potential NFS clients. It verifies that each client has
permission to mount the requested directories.
amd and automount: mount filesystems on demand
amd and automount are NFS automounters, daemons that wait until a process attempts to use a filesystem
before they actually mount it. The automounters later unmount the filesystems if they have not been
accessed in a specified period of time.
rpc.lockd and rpc.statd:manage NFS locks
Although rpc.lockd and rpc.statd are distinct daemons, they always run as a team. rpc.lockd maintains
advisory locks (a la flock and lockf) on NFS files. rpc.statd allows processes to monitor the status of other
machines that are running NFS. rpc.lockd uses rpc.statd to decide when to attempt to communicate with a
remote machine.
rpciod: cache NFS blocks
rpciod caches read and write requests on NFS clients. It performs both read-ahead and write-behind
buffering and greatly improves the performance of NFS. This daemon is analogous to the biod and
nfsiod daemons found on other systems, although it is structurally somewhat different.
smbd:provide file and printing service to Windows clients
smbd is the file and printer server in the Samba suite. It provides file and printer sharing service
through the Windows protocol known variously as SMB or CIFS.
Page 5 of 8
ADMINISTRATIVE DATABASE DAEMONS
Several daemons are associated with Sun’s NIS administrative database system. Sharing System Files.
Although NIS originated at Sun, it is now used on many other vendors’ systems as well, including
Linux.
ELECTRONIC MAIL DAEMONS
In addition to the core sendmail and Postfix mail delivery systems, which are both in widespread use,
severaldaemons facilitate remote access to mailboxes.
sendmail: transport electronic mail
sendmail’s tasks include accepting messages from users and remote sites, rewriting addresses, expanding
aliases, and transferring mail across the Internet. sendmail is an important and very complex daemon.
smtpd: Simple Mail TransportProtocoldaemon
smtpd listens on port 25 for incoming email messages and forwards them to your back-end transport
system for further processing.
popd:basic mailbox server
The popd daemon implements the Post Office Protocol (POP). This protocol is commonly used by non-
Linux systems to receive electronic mail.
imapd: deluxe mailbox server
The imapd daemon implements the Internet Message Access Protocol,IMAP,which is a more festive and
featureful alternative to POP. It allows PC-based users (or Linux users with IMAP-enabled mail readers)
to access their email from a variety of locations, with mail folders being stored on the Linux server. Check
out www.imap.org for more information about IMAP.
REMOTE LOGIN AND COMMAND EXECUTION DAEMONS
The ability to log in and execute commands over the net was one of the earliest motivations for the
development of UNIX networking, and this facility is still a bread and-butter component of system
administration today. Unfortunately, it took the UNIX community severaldecades to achieve a mature
appreciation of the security implications of this technology. Modern production systems should be
using SSH (sshd) and virtually nothing else.
Page 6 of 8
Daemon Process Design
A daemon process can be developed just like any other process but there is one thing that differentiates it
with any other normal process ie having no controlling terminal. This is a major design aspect in creating
a daemon process. This can be achieved by
 Create a normal process (Parent process)
 Create a child process from within the above parent process
 The process hierarchy at this stage looks like: TERMINAL -> PARENT PROCESS -> CHILD
PROCESS
 Terminate the parent process.
 The child process now becomes orphan and is taken over by the init process.
init (short for initialization) is the first process started during booting of the
computer system. Init is a daemon process that continues running until the
system is shut down.
 Call setsid () function to run the process in new session and have a new group.
 After the above step we can say that now this process becomes a daemon process without having
a controlling terminal.
 Change the working directory of the daemon process to root and close stdin, stdout and stderr file
descriptors.
 Let the main logic of daemon process run.
The Implementation of deamon process programmatically
Before starting the implementation ofdeamon process let’s discuss the basic knowledge ofa fork ()
system call that is used to create the child process and parent also. fork () system creates a child
process that is exact replica ofthe parent process. This newprocess is referred as ‘child’ process.
This system call gets called once (in parent process) but returns twice (once in parent and second time in
child). Note that after the fork () system call, whether the parent will run first or the child is non-
deterministic. It purely depends on the context switch mechanism. This call returns zero in child while
returns PID of child process in the parent process.
Following are some important aspects of this call
 The child has its own unique process ID,and this PID does not match the ID of any existing
process group.
 The child’s parent process ID is the same as the parent’s process ID.
 The child does not inherit its parent’s memory locks.
 Process resource utilization and CPU time counters are reset to zero in the child.
 The child’s set of pending signals is initially empty.
 The child does not inherit semaphore adjustments from its parent.
 The child does not inherit record locks from its parent.
 The child does not inherit timers from its parent.
 The child does not inherit outstanding asynchronous I/O operations from its parent, nor does it
inherit any asynchronous I/O contexts from its parent.
Page 7 of 8
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <string.h>
 The variables are named argc (argument count) and argv (argument vector)
int main (int argc, char* argv[])
{
FILE *fp= NULL;
pid_t process_id = 0;
pid_t sid = 0;
// Create child process
process_id = fork ();
// Indication of fork () failure
if (process_id < 0){
printf ("fork failed! n");
// Return failure in exit status
exit (1);
}
// PARENT PROCESS. Need to kill it.
if (process_id > 0) {
printf ("process_id of child process %d n", process_id);
// return success in exit status
exit (0);
}
//unmask the file mode
umask (0);
//set new session
sid = setsid ();
if (sid < 0) {
// Return failure
exit (1);
}
// Change the current working directory to root.
chdir ("/");
// Close stdin. stdout and stderr
close (STDIN_FILENO);
close (STDOUT_FILENO);
close (STDERR_FILENO);
// Open a log file in write mode.
fp = fopen ("Log.txt", "w+");
while (1) {
//Dont block context switches, let the process sleep for some time
sleep (1);
fprintf (fp, "Logging info...n");
fflush(fp);
// Implement and call some function that does core work for this daemon.
}
fclose(fp);
return (0);
}
Following is the way through which the code was compiled and executed:
Page 8 of 8
$ gcc -Wall deamon.c -o deamon
$ sudo. /deamon
process_id of child process 2936
When we check the log.txt file located in the root directory, you could see that this daemon
process is running.
$ tail -f /Log.txt
Logging info...
Logging info...
Logging info...
Logging info...
Logging info...
Logging info...
Batch programming
Unix basic commands
Scripts..
System Calls (Important Topic)
30 MCQ’s
Shell Programming (Q.NO 2 program-3program+theoratical)
System Calls (Q,NO 4,5,6)

More Related Content

What's hot

Process and Threads in Linux - PPT
Process and Threads in Linux - PPTProcess and Threads in Linux - PPT
Process and Threads in Linux - PPTQUONTRASOLUTIONS
 
Linux server world
Linux server worldLinux server world
Linux server worldAkshat Singh
 
Systemd for developers
Systemd for developersSystemd for developers
Systemd for developersAlison Chaiken
 
Analysis of interrupt latencies in a real-time kernel
Analysis of interrupt latencies in a real-time kernelAnalysis of interrupt latencies in a real-time kernel
Analysis of interrupt latencies in a real-time kernelGabriele Modena
 
Linux architecture
Linux architectureLinux architecture
Linux architecturemcganesh
 
Windows Internals for Linux Kernel Developers
Windows Internals for Linux Kernel DevelopersWindows Internals for Linux Kernel Developers
Windows Internals for Linux Kernel DevelopersKernel TLV
 
Testing real-time Linux. What to test and how
Testing real-time Linux. What to test and how Testing real-time Linux. What to test and how
Testing real-time Linux. What to test and how Chirag Jog
 
Linux26 New Features
Linux26 New FeaturesLinux26 New Features
Linux26 New Featuresguest491c69
 
linux interview questions and answers
linux interview questions and answerslinux interview questions and answers
linux interview questions and answersGanapathi Raju
 
Linux System Monitoring basic commands
Linux System Monitoring basic commandsLinux System Monitoring basic commands
Linux System Monitoring basic commandsMohammad Rafiee
 
Kernel Recipes 2015: Linux Kernel IO subsystem - How it works and how can I s...
Kernel Recipes 2015: Linux Kernel IO subsystem - How it works and how can I s...Kernel Recipes 2015: Linux Kernel IO subsystem - How it works and how can I s...
Kernel Recipes 2015: Linux Kernel IO subsystem - How it works and how can I s...Anne Nicolas
 
Real-time soultion
Real-time soultionReal-time soultion
Real-time soultionNylon
 
CLUG 2010 09 - systemd - the new init system
CLUG 2010 09 - systemd - the new init systemCLUG 2010 09 - systemd - the new init system
CLUG 2010 09 - systemd - the new init systemPaulWay
 
A Reimplementation of NetBSD Based on a Microkernel by Andrew S. Tanenbaum
A Reimplementation of NetBSD Based on a Microkernel by Andrew S. TanenbaumA Reimplementation of NetBSD Based on a Microkernel by Andrew S. Tanenbaum
A Reimplementation of NetBSD Based on a Microkernel by Andrew S. Tanenbaumeurobsdcon
 
Tuning systemd for embedded
Tuning systemd for embeddedTuning systemd for embedded
Tuning systemd for embeddedAlison Chaiken
 
IRQs: the Hard, the Soft, the Threaded and the Preemptible
IRQs: the Hard, the Soft, the Threaded and the PreemptibleIRQs: the Hard, the Soft, the Threaded and the Preemptible
IRQs: the Hard, the Soft, the Threaded and the PreemptibleAlison Chaiken
 
Solving Real-Time Scheduling Problems With RT_PREEMPT and Deadline-Based Sche...
Solving Real-Time Scheduling Problems With RT_PREEMPT and Deadline-Based Sche...Solving Real-Time Scheduling Problems With RT_PREEMPT and Deadline-Based Sche...
Solving Real-Time Scheduling Problems With RT_PREEMPT and Deadline-Based Sche...peknap
 

What's hot (20)

Process and Threads in Linux - PPT
Process and Threads in Linux - PPTProcess and Threads in Linux - PPT
Process and Threads in Linux - PPT
 
Linux server world
Linux server worldLinux server world
Linux server world
 
Systemd for developers
Systemd for developersSystemd for developers
Systemd for developers
 
Analysis of interrupt latencies in a real-time kernel
Analysis of interrupt latencies in a real-time kernelAnalysis of interrupt latencies in a real-time kernel
Analysis of interrupt latencies in a real-time kernel
 
Linux architecture
Linux architectureLinux architecture
Linux architecture
 
Windows Internals for Linux Kernel Developers
Windows Internals for Linux Kernel DevelopersWindows Internals for Linux Kernel Developers
Windows Internals for Linux Kernel Developers
 
Testing real-time Linux. What to test and how
Testing real-time Linux. What to test and how Testing real-time Linux. What to test and how
Testing real-time Linux. What to test and how
 
Linux26 New Features
Linux26 New FeaturesLinux26 New Features
Linux26 New Features
 
linux interview questions and answers
linux interview questions and answerslinux interview questions and answers
linux interview questions and answers
 
Linux System Monitoring basic commands
Linux System Monitoring basic commandsLinux System Monitoring basic commands
Linux System Monitoring basic commands
 
Kernel Recipes 2015: Linux Kernel IO subsystem - How it works and how can I s...
Kernel Recipes 2015: Linux Kernel IO subsystem - How it works and how can I s...Kernel Recipes 2015: Linux Kernel IO subsystem - How it works and how can I s...
Kernel Recipes 2015: Linux Kernel IO subsystem - How it works and how can I s...
 
Real-time soultion
Real-time soultionReal-time soultion
Real-time soultion
 
First steps on CentOs7
First steps on CentOs7First steps on CentOs7
First steps on CentOs7
 
CLUG 2010 09 - systemd - the new init system
CLUG 2010 09 - systemd - the new init systemCLUG 2010 09 - systemd - the new init system
CLUG 2010 09 - systemd - the new init system
 
A Reimplementation of NetBSD Based on a Microkernel by Andrew S. Tanenbaum
A Reimplementation of NetBSD Based on a Microkernel by Andrew S. TanenbaumA Reimplementation of NetBSD Based on a Microkernel by Andrew S. Tanenbaum
A Reimplementation of NetBSD Based on a Microkernel by Andrew S. Tanenbaum
 
Tuning systemd for embedded
Tuning systemd for embeddedTuning systemd for embedded
Tuning systemd for embedded
 
IRQs: the Hard, the Soft, the Threaded and the Preemptible
IRQs: the Hard, the Soft, the Threaded and the PreemptibleIRQs: the Hard, the Soft, the Threaded and the Preemptible
IRQs: the Hard, the Soft, the Threaded and the Preemptible
 
Solving Real-Time Scheduling Problems With RT_PREEMPT and Deadline-Based Sche...
Solving Real-Time Scheduling Problems With RT_PREEMPT and Deadline-Based Sche...Solving Real-Time Scheduling Problems With RT_PREEMPT and Deadline-Based Sche...
Solving Real-Time Scheduling Problems With RT_PREEMPT and Deadline-Based Sche...
 
Linux kernel
Linux kernelLinux kernel
Linux kernel
 
Hdfs high availability
Hdfs high availabilityHdfs high availability
Hdfs high availability
 

Similar to Project of deamon process

Linux Daemons & INIT services
Linux Daemons & INIT servicesLinux Daemons & INIT services
Linux Daemons & INIT servicesomkar bhagat
 
17 Linux Basics #burningkeyboards
17 Linux Basics #burningkeyboards17 Linux Basics #burningkeyboards
17 Linux Basics #burningkeyboardsDenis Ristic
 
Linux Cheat Sheet.pdf
Linux Cheat Sheet.pdfLinux Cheat Sheet.pdf
Linux Cheat Sheet.pdfroschahacker
 
Operating System basics Introduction
Operating System basics IntroductionOperating System basics Introduction
Operating System basics IntroductionPoornima E.G.
 
Containers with systemd-nspawn
Containers with systemd-nspawnContainers with systemd-nspawn
Containers with systemd-nspawnGábor Nyers
 
Linux@assignment ppt
Linux@assignment pptLinux@assignment ppt
Linux@assignment pptRama .
 
Squid proxy-configuration-guide
Squid proxy-configuration-guideSquid proxy-configuration-guide
Squid proxy-configuration-guidejasembo
 
18587936 squid-proxy-configuration-guide - [the-xp.blogspot.com]
18587936 squid-proxy-configuration-guide - [the-xp.blogspot.com]18587936 squid-proxy-configuration-guide - [the-xp.blogspot.com]
18587936 squid-proxy-configuration-guide - [the-xp.blogspot.com]Krisman Tarigan
 
Virtual Distro Dispatcher - A costless distributed virtual environment from T...
Virtual Distro Dispatcher - A costless distributed virtual environment from T...Virtual Distro Dispatcher - A costless distributed virtual environment from T...
Virtual Distro Dispatcher - A costless distributed virtual environment from T...Flavio Bertini
 

Similar to Project of deamon process (20)

Linux Daemons & INIT services
Linux Daemons & INIT servicesLinux Daemons & INIT services
Linux Daemons & INIT services
 
.ppt
.ppt.ppt
.ppt
 
Linux
LinuxLinux
Linux
 
17 Linux Basics #burningkeyboards
17 Linux Basics #burningkeyboards17 Linux Basics #burningkeyboards
17 Linux Basics #burningkeyboards
 
Walking around linux kernel
Walking around linux kernelWalking around linux kernel
Walking around linux kernel
 
Linux Cheat Sheet.pdf
Linux Cheat Sheet.pdfLinux Cheat Sheet.pdf
Linux Cheat Sheet.pdf
 
linux
linuxlinux
linux
 
Hpc4 linux advanced
Hpc4 linux advancedHpc4 linux advanced
Hpc4 linux advanced
 
Os
OsOs
Os
 
Operating System basics Introduction
Operating System basics IntroductionOperating System basics Introduction
Operating System basics Introduction
 
FreeBSD Portscamp, Kuala Lumpur 2016
FreeBSD Portscamp, Kuala Lumpur 2016FreeBSD Portscamp, Kuala Lumpur 2016
FreeBSD Portscamp, Kuala Lumpur 2016
 
Containers with systemd-nspawn
Containers with systemd-nspawnContainers with systemd-nspawn
Containers with systemd-nspawn
 
Linux@assignment ppt
Linux@assignment pptLinux@assignment ppt
Linux@assignment ppt
 
Squid proxy-configuration-guide
Squid proxy-configuration-guideSquid proxy-configuration-guide
Squid proxy-configuration-guide
 
Operating system ppt
Operating system pptOperating system ppt
Operating system ppt
 
Operating system ppt
Operating system pptOperating system ppt
Operating system ppt
 
Operating system ppt
Operating system pptOperating system ppt
Operating system ppt
 
Operating system ppt
Operating system pptOperating system ppt
Operating system ppt
 
18587936 squid-proxy-configuration-guide - [the-xp.blogspot.com]
18587936 squid-proxy-configuration-guide - [the-xp.blogspot.com]18587936 squid-proxy-configuration-guide - [the-xp.blogspot.com]
18587936 squid-proxy-configuration-guide - [the-xp.blogspot.com]
 
Virtual Distro Dispatcher - A costless distributed virtual environment from T...
Virtual Distro Dispatcher - A costless distributed virtual environment from T...Virtual Distro Dispatcher - A costless distributed virtual environment from T...
Virtual Distro Dispatcher - A costless distributed virtual environment from T...
 

More from Abubakr Cheema

Mobile app development agreement february 18 2020
Mobile app development agreement   february 18 2020Mobile app development agreement   february 18 2020
Mobile app development agreement february 18 2020Abubakr Cheema
 
Pharmacy management system fyp documentation
Pharmacy management system fyp documentationPharmacy management system fyp documentation
Pharmacy management system fyp documentationAbubakr Cheema
 
Mobile/Web App Development Project Report
Mobile/Web App Development Project ReportMobile/Web App Development Project Report
Mobile/Web App Development Project ReportAbubakr Cheema
 
Presentation On new Product development
Presentation On new Product developmentPresentation On new Product development
Presentation On new Product developmentAbubakr Cheema
 
EXTERNAL GROWTH STRATEGIES
EXTERNAL GROWTH STRATEGIESEXTERNAL GROWTH STRATEGIES
EXTERNAL GROWTH STRATEGIESAbubakr Cheema
 
Intel-Processor 80286
                                            Intel-Processor 80286                                            Intel-Processor 80286
Intel-Processor 80286Abubakr Cheema
 
Gen. Ayub Khan's Decade
Gen. Ayub Khan's DecadeGen. Ayub Khan's Decade
Gen. Ayub Khan's DecadeAbubakr Cheema
 

More from Abubakr Cheema (8)

Mobile app development agreement february 18 2020
Mobile app development agreement   february 18 2020Mobile app development agreement   february 18 2020
Mobile app development agreement february 18 2020
 
Pharmacy management system fyp documentation
Pharmacy management system fyp documentationPharmacy management system fyp documentation
Pharmacy management system fyp documentation
 
Project timeline
Project timelineProject timeline
Project timeline
 
Mobile/Web App Development Project Report
Mobile/Web App Development Project ReportMobile/Web App Development Project Report
Mobile/Web App Development Project Report
 
Presentation On new Product development
Presentation On new Product developmentPresentation On new Product development
Presentation On new Product development
 
EXTERNAL GROWTH STRATEGIES
EXTERNAL GROWTH STRATEGIESEXTERNAL GROWTH STRATEGIES
EXTERNAL GROWTH STRATEGIES
 
Intel-Processor 80286
                                            Intel-Processor 80286                                            Intel-Processor 80286
Intel-Processor 80286
 
Gen. Ayub Khan's Decade
Gen. Ayub Khan's DecadeGen. Ayub Khan's Decade
Gen. Ayub Khan's Decade
 

Recently uploaded

GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfAlina Yurenko
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...OnePlan Solutions
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...Christina Lin
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Andreas Granig
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...soniya singh
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEEVICTOR MAESTRE RAMIREZ
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based projectAnoyGreter
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideChristina Lin
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantAxelRicardoTrocheRiq
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样umasea
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...stazi3110
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software DevelopersVinodh Ram
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...gurkirankumar98700
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...MyIntelliSource, Inc.
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEOrtus Solutions, Corp
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaHanief Utama
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWave PLM
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - InfographicHr365.us smith
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...MyIntelliSource, Inc.
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024StefanoLambiase
 

Recently uploaded (20)

GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdfGOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
GOING AOT WITH GRAALVM – DEVOXX GREECE.pdf
 
Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...Advancing Engineering with AI through the Next Generation of Strategic Projec...
Advancing Engineering with AI through the Next Generation of Strategic Projec...
 
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
ODSC - Batch to Stream workshop - integration of Apache Spark, Cassandra, Pos...
 
Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024Automate your Kamailio Test Calls - Kamailio World 2024
Automate your Kamailio Test Calls - Kamailio World 2024
 
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
Russian Call Girls in Karol Bagh Aasnvi ➡️ 8264348440 💋📞 Independent Escort S...
 
Cloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEECloud Data Center Network Construction - IEEE
Cloud Data Center Network Construction - IEEE
 
MYjobs Presentation Django-based project
MYjobs Presentation Django-based projectMYjobs Presentation Django-based project
MYjobs Presentation Django-based project
 
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop SlideBuilding Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
Building Real-Time Data Pipelines: Stream & Batch Processing workshop Slide
 
Salesforce Certified Field Service Consultant
Salesforce Certified Field Service ConsultantSalesforce Certified Field Service Consultant
Salesforce Certified Field Service Consultant
 
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
办理学位证(UQ文凭证书)昆士兰大学毕业证成绩单原版一模一样
 
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
Building a General PDE Solving Framework with Symbolic-Numeric Scientific Mac...
 
Professional Resume Template for Software Developers
Professional Resume Template for Software DevelopersProfessional Resume Template for Software Developers
Professional Resume Template for Software Developers
 
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
(Genuine) Escort Service Lucknow | Starting ₹,5K To @25k with A/C 🧑🏽‍❤️‍🧑🏻 89...
 
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
Steps To Getting Up And Running Quickly With MyTimeClock Employee Scheduling ...
 
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASEBATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
BATTLEFIELD ORM: TIPS, TACTICS AND STRATEGIES FOR CONQUERING YOUR DATABASE
 
React Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief UtamaReact Server Component in Next.js by Hanief Utama
React Server Component in Next.js by Hanief Utama
 
What is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need ItWhat is Fashion PLM and Why Do You Need It
What is Fashion PLM and Why Do You Need It
 
Asset Management Software - Infographic
Asset Management Software - InfographicAsset Management Software - Infographic
Asset Management Software - Infographic
 
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
Try MyIntelliAccount Cloud Accounting Software As A Service Solution Risk Fre...
 
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
Dealing with Cultural Dispersion — Stefano Lambiase — ICSE-SEIS 2024
 

Project of deamon process

  • 1. Page 1 of 8 Semester Project . Deamon Process . BSCS (B) Semester 8th Batch 2016- 2020 Course # System Programming Submitted by Submitted to Abu-Bakr G1F16BSCS0076 Pro. Umer Iftikhar Zain Khalid G1F16BSCS0143 University Of Central Punjab Gujranwala Campus
  • 2. Page 2 of 8 Deamon Process A daemon process is a process which runs in background and has no controlling terminal. A daemon (also known as background processes) is UNIX and it is known as services and agents in windows. Since a daemon process usually has no controlling terminal so almost no user interaction is required. Daemon processes are used to provide services that can well be done in background without any user interaction. Daemons are processes that are often started when the system is bootstrapped (boot time) and terminate only when the system is shut down. Command used to check deamon processes ps -axj  -a option shows the status of processes owned by others,  -x shows processes that don't have a controlling terminal.  -j option displays the job-related information: the o session ID o process group ID o controlling terminal o terminal process group ID. Characteristics  A daemon is long-lived, often created at system startup and runs until the system is shut down  It runs in the background and has no controlling terminal. The lack of a controlling terminal ensures that the kernel never automatically generates any terminal-related signals for a daemon Almost all daemons have names that end with the letter "d". For example, httpd the daemon that handles the Apache server,or, sshd which handles SSH remote access connections. Some popular Categories of deamons are as follow KERNEL DAEMONS  Deamons jo kernel leve services provide kertatay hain, and cannot be manuplated by system adminstrator jesay k example next page For architectural reasons,a few parts of the Linux kernel are managed as if they were user processes. On older kernels, these processes could be identified by their low PIDs and names that start with k, such as kupdate, kswapd, keventd, and kapm. The naming is less consistent under the 2.6 kernels, but ps always shows the names of kernel threads in square brackets. For the most part, these processes dealwith various aspects of I/O, memory management, and synchronization of the disk cache. They cannot be manipulated by the system administrator and should be left alone. Daemons that include an N parameter in their names
  • 3. Page 3 of 8 Port numbers are not arbitrary. All machines must agree about which services go with which ports; otherwise, requests will constantly be directed to the wrong port. If you are creating a site-specific service, pick a high port number (greater than 1023) that is not already listed in the services file. If you are familiar with the implementation of the kernel, it is occasionally useful to change these processes’ execution priorities. However,this is not a standard administrative task. Daemons (as shown by ps) run separately on each CPU of a multi-CPU system; the N tells you which copy goes with which CPU. Major kernel daemons Daemon Function  ksoftirqd/N Handles software interrupts when the load is high  kacpid Deals with the ACPI subsystem  kblockd/N Blocks subsystem work  aio/N Retries asynchronous I/Os  kswapdN Moves pages to swap  ata/N Does processing for serial ATA support  scsi_eh_N Performs SCSI error handling  kjournald Supports journaling filesystems  events/N Does generic work queue processing PRINTING DAEMONS Several printing systems are in common use, and each has its own family of commands and daemons that  provide printing-related services. In some cases,the families have been hybridized; in others cases,multiple variants run on a single system. cupsd:scheduler for the Common UNIX Printing System CUPS provide a portable printing facility by implementing version 1.1 of the Internet Printing Protocol. It allows remote users to print to their offices (or vice versa) by using a web interface. CUPS has become quite popular and is most systems’ default printing manager. It is flexible enough to allow for remote authentication. lpd: manage printing lpd is responsible for the old-style BSD print spooling system. It accepts jobs from users and forks processes that perform the actual printing. lpd is also responsible for transferring print jobs to and from remote systems. lpd can sometimes hang and then must be manually restarted.
  • 4. Page 4 of 8 FILE SERVICE DAEMONS The following daemons are part of the NFS(Network File System) or Samba file sharing systems. We give only a brief description of their functions here. NFS is described in detail in Chapter 16, and Samba is covered starting on page 828. rpc.nfsd:serve files rpc.nfsd runs on file servers and handles requests from NFS clients. In most NFS implementations, nfsd is really just a part of the kernel that has been dressed up as a process for scheduling reasons. Linux actually sports two different implementations, one of which follows this convention and one of which runs in user space. The kernel implementation is more popular and is most distributions’ default. rpc.nfsd accepts a single argument that specifies how many copies of itself to fork. rpc.mountd:respond to mount requests rpc.mountd accepts filesystem mount requests from potential NFS clients. It verifies that each client has permission to mount the requested directories. amd and automount: mount filesystems on demand amd and automount are NFS automounters, daemons that wait until a process attempts to use a filesystem before they actually mount it. The automounters later unmount the filesystems if they have not been accessed in a specified period of time. rpc.lockd and rpc.statd:manage NFS locks Although rpc.lockd and rpc.statd are distinct daemons, they always run as a team. rpc.lockd maintains advisory locks (a la flock and lockf) on NFS files. rpc.statd allows processes to monitor the status of other machines that are running NFS. rpc.lockd uses rpc.statd to decide when to attempt to communicate with a remote machine. rpciod: cache NFS blocks rpciod caches read and write requests on NFS clients. It performs both read-ahead and write-behind buffering and greatly improves the performance of NFS. This daemon is analogous to the biod and nfsiod daemons found on other systems, although it is structurally somewhat different. smbd:provide file and printing service to Windows clients smbd is the file and printer server in the Samba suite. It provides file and printer sharing service through the Windows protocol known variously as SMB or CIFS.
  • 5. Page 5 of 8 ADMINISTRATIVE DATABASE DAEMONS Several daemons are associated with Sun’s NIS administrative database system. Sharing System Files. Although NIS originated at Sun, it is now used on many other vendors’ systems as well, including Linux. ELECTRONIC MAIL DAEMONS In addition to the core sendmail and Postfix mail delivery systems, which are both in widespread use, severaldaemons facilitate remote access to mailboxes. sendmail: transport electronic mail sendmail’s tasks include accepting messages from users and remote sites, rewriting addresses, expanding aliases, and transferring mail across the Internet. sendmail is an important and very complex daemon. smtpd: Simple Mail TransportProtocoldaemon smtpd listens on port 25 for incoming email messages and forwards them to your back-end transport system for further processing. popd:basic mailbox server The popd daemon implements the Post Office Protocol (POP). This protocol is commonly used by non- Linux systems to receive electronic mail. imapd: deluxe mailbox server The imapd daemon implements the Internet Message Access Protocol,IMAP,which is a more festive and featureful alternative to POP. It allows PC-based users (or Linux users with IMAP-enabled mail readers) to access their email from a variety of locations, with mail folders being stored on the Linux server. Check out www.imap.org for more information about IMAP. REMOTE LOGIN AND COMMAND EXECUTION DAEMONS The ability to log in and execute commands over the net was one of the earliest motivations for the development of UNIX networking, and this facility is still a bread and-butter component of system administration today. Unfortunately, it took the UNIX community severaldecades to achieve a mature appreciation of the security implications of this technology. Modern production systems should be using SSH (sshd) and virtually nothing else.
  • 6. Page 6 of 8 Daemon Process Design A daemon process can be developed just like any other process but there is one thing that differentiates it with any other normal process ie having no controlling terminal. This is a major design aspect in creating a daemon process. This can be achieved by  Create a normal process (Parent process)  Create a child process from within the above parent process  The process hierarchy at this stage looks like: TERMINAL -> PARENT PROCESS -> CHILD PROCESS  Terminate the parent process.  The child process now becomes orphan and is taken over by the init process. init (short for initialization) is the first process started during booting of the computer system. Init is a daemon process that continues running until the system is shut down.  Call setsid () function to run the process in new session and have a new group.  After the above step we can say that now this process becomes a daemon process without having a controlling terminal.  Change the working directory of the daemon process to root and close stdin, stdout and stderr file descriptors.  Let the main logic of daemon process run. The Implementation of deamon process programmatically Before starting the implementation ofdeamon process let’s discuss the basic knowledge ofa fork () system call that is used to create the child process and parent also. fork () system creates a child process that is exact replica ofthe parent process. This newprocess is referred as ‘child’ process. This system call gets called once (in parent process) but returns twice (once in parent and second time in child). Note that after the fork () system call, whether the parent will run first or the child is non- deterministic. It purely depends on the context switch mechanism. This call returns zero in child while returns PID of child process in the parent process. Following are some important aspects of this call  The child has its own unique process ID,and this PID does not match the ID of any existing process group.  The child’s parent process ID is the same as the parent’s process ID.  The child does not inherit its parent’s memory locks.  Process resource utilization and CPU time counters are reset to zero in the child.  The child’s set of pending signals is initially empty.  The child does not inherit semaphore adjustments from its parent.  The child does not inherit record locks from its parent.  The child does not inherit timers from its parent.  The child does not inherit outstanding asynchronous I/O operations from its parent, nor does it inherit any asynchronous I/O contexts from its parent.
  • 7. Page 7 of 8 #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <sys/types.h> #include <sys/stat.h> #include <string.h>  The variables are named argc (argument count) and argv (argument vector) int main (int argc, char* argv[]) { FILE *fp= NULL; pid_t process_id = 0; pid_t sid = 0; // Create child process process_id = fork (); // Indication of fork () failure if (process_id < 0){ printf ("fork failed! n"); // Return failure in exit status exit (1); } // PARENT PROCESS. Need to kill it. if (process_id > 0) { printf ("process_id of child process %d n", process_id); // return success in exit status exit (0); } //unmask the file mode umask (0); //set new session sid = setsid (); if (sid < 0) { // Return failure exit (1); } // Change the current working directory to root. chdir ("/"); // Close stdin. stdout and stderr close (STDIN_FILENO); close (STDOUT_FILENO); close (STDERR_FILENO); // Open a log file in write mode. fp = fopen ("Log.txt", "w+"); while (1) { //Dont block context switches, let the process sleep for some time sleep (1); fprintf (fp, "Logging info...n"); fflush(fp); // Implement and call some function that does core work for this daemon. } fclose(fp); return (0); } Following is the way through which the code was compiled and executed:
  • 8. Page 8 of 8 $ gcc -Wall deamon.c -o deamon $ sudo. /deamon process_id of child process 2936 When we check the log.txt file located in the root directory, you could see that this daemon process is running. $ tail -f /Log.txt Logging info... Logging info... Logging info... Logging info... Logging info... Logging info... Batch programming Unix basic commands Scripts.. System Calls (Important Topic) 30 MCQ’s Shell Programming (Q.NO 2 program-3program+theoratical) System Calls (Q,NO 4,5,6)