Connect with us

FACEBOOK

Facebook Marketing: Promote your Facebook Page and Posts

Published

on

Facebook is one of the biggest giants in the social media industry. It has billions of active user accounts. Hundreds of millions of people use Facebook daily. This is why it is a good platform to promote your brand and get people to purchase your products and services.

A lot of people report that they have bought something after seeing it on social media. So, if you think this is what your brand needs then Facebook marketing is for you. In this post, we will cover a lot of things. We will like to start with some paid services to help you with Facebook marketing. Don’t worry, if you want to stay for free then we have a comprehensive guide for Facebook marketing strategy at the bottom. Check it out.

List of Sites to Buy Facebook Likes

One of the methods to improve the presence on Facebook that are popular these days is buying likes or other stats. The concept behind this is that social media is all about social proof. If people see that a post or a page has lots of likes, comments, etc. then they will be willing to engage with it too. The herd mentality is at play here.

This is why buying likes can boost your stats and thus, all you need to do is promote your content as best as you can and hope that people notice your posts and engage with them. Of course, if the quality or the content of the post isn’t good this method will not help. Below are some sites which provide the services to buy Facebook likes.

Viralyft

Viralyft is a social media service provider which means that it sells a variety of social media stats. The cost of Facebook page likes on Viralyft starts at $18 for 500 likes. The starting rate for Facebook post likes is $5.99 for 100 likes.

Advertisement
free widgets for website

GetViral.io

This is another social media service provider. It has services for many different platforms like Instagram, Facebook, SoundCloud, Twitch, Spotify, Twitter, YouTube, and TikTok. It has many packages for Facebook page likes.

The cheapest one provides you with 500 likes for around $17.

ViewsExpert

ViewsExpert has a vast network that the clients can utilize to improve their online presence on the many social media platforms. This company does not provide services for Facebook post likes but you can buy Facebook page likes for which the price starts at $16.50 for 500 likes.

SocialPackages

SocialPackages is a company that focuses mostly on Instagram and claims to be the best at providing services for that platform. But it has services for many different social media platforms as well.

The company sells Facebook page likes. The base package gives you 250 likes for $10.

Advertisement
free widgets for website

Fastlikes.io

The last service provider on this list is Fastlikes.io. It is a company that says that if you want to follow the trending way to visit your popularity on social media then use its services. It has services for Spotify, YouTube, Facebook, Instagram, SoundCloud, and Twitter. The base package for Facebook page likes for this site starts at $17 and provides you with 500 likes.

Facebook Marketing Agencies

Marketing agencies are companies that can help boost your brand awareness by the use of various methods. This list contains 5 marketing agencies that provide services to help boost the performance of your page on Facebook. If you lack the correct idea and are stuck with promoting on Facebook these companies can help. So, check them out.

FullyDigital

FullyDigital is a marketing agency that provides a variety of services to help businesses with their digital marketing needs. It provides services for search engine optimization, social media marketing, and app development.

The company believes in its team and says that the team will use all the experience and expertise to help you succeed online. Social media marketing services cost around $249 per month which is the base package.

GrowBranding

GrowBranding is a full-service marketing agency that provides all kinds of digital marketing services. You can get services for social media marketing, web development, search engine optimization, software development, mobile application development, and web design.

Advertisement
free widgets for website

Visit the website if you want to get in touch with the company and get a quote on the service you are looking for.

LabelFirm

LabelFirm is a company that provides a wide variety of services. If you are looking to improve the online reach of your business and need help or support regarding that then LabelFirm has got the appropriate services for you.

The base package for availing of the services of this agency is $199 per month.

SkyBranding

The next company on this list is SkyBranding. This is a company that has made the success of the clients its mission. It provides premium services with timely delivery and consistent 24/7 support.

It provides all kinds of services including software development, web development, social media marketing, social media management, mobile app development, and search engine optimization.

Advertisement
free widgets for website

Shoutzer

Shoutzer is a company that provides all the services that you can expect from a company providing digital marketing services to clients. One of these services is social media marketing which is what you must be looking for Facebook marketing purposes.

So, visit the website for more details on the services and get in touch with the company.

Facebook Marketing Complete Guide

So, far we have seen some of the companies and websites that one can use to get a leg up on their competitors on Facebook. Facebook marketing has many facets that one needs to know if one wants to be successful at it. Of course, the above companies can be of help but knowing about Facebook marketing and what it entails can help you not only understand the work that these companies will be doing for you but also help you better use the service that they provide you with.

So, we decided to give you a full-course meal on this topic and try to cover a lot of things. We have divided this guide into many sections for ease of your understanding. If you think you have a fair idea about one thing then you can skip it and move on to the next section. So, let’s get into it.

Setting Up Facebook Business Page

The first thing that one needs to take care of while trying to start with Facebook marketing is to have a Facebook business page. The whole thing isn’t that difficult technically. You can get started with it in just a few minutes. But what takes time is setting it up in a way that it becomes useful for your business and people actually get good info about your business from the page.

Advertisement
free widgets for website

When a user goes to your business page they need to be able to get enough idea about your business and click on a link to either get in touch with you or go to your store or website as applicable. In this section of the guide, we decided to go over the steps of creating a Facebook business page and also take care of some of the nuances that can make it more effective for your business or brand.

  • Have a Facebook Account

Well, you need to have a personal Facebook account if you are looking to create a Facebook page for your business. If you already have one you can log into it or sign up on Facebook to create a new account. Even if you use your personal account to create a business page you don’t have to worry.

None of your personal information will be visible on the page that you create. So, you can create your Facebook business page using your personal account without having to worry much.

  • Creating A Page

For this, you have to visit the URL facebook.com/pages/create. Once you visit this link you will be asked to choose from a couple of options to create a page. You can either choose to create a community/public figure page in which case it will be linked to a particular celebrity or influencer or to any community.

The other option is what we are interested in. This option is business/brand. Since you want to create a Facebook business page you will have to select this option and click on the get started button below that option. This will start the creation process of the page.

  • Entering Relevant Business Info

Once you click on the get started button for the business/brand option you will now need to enter relevant information about your business. The name of the page will be the same as the name of your business. This will help people find your page easily if they are looking for your business or brand.

Next, you need to add a category. This is generally the category that your business falls under. You can type a few words to describe your business on the category search bar. Once you put something relevant Facebook will start suggesting category options. Select the one which matches your business category.

Once this is done Facebook will ask you to provide certain information like phone number, address details, etc. If you don’t want to keep all the information visible to the public you can do so and only keep the city or state your business is in, public. Click on Continue once you are done with this.

Advertisement
free widgets for website
  • Time to Upload Images

Now, it is time to make your page look good and professional. A nice profile pic and a cover image are very important if you want to ensure that people who end up on your page stay on it. Oftentimes, it is a visual one. So, the pics that you upload should be clear and of good quality so that it is able to provide a positive visual impression to the users.

See also  Reflecting on a year of innovation with our developer and creator ecosystem

The profile pic is one of the first pic users will generally see. It pops up next to your business name on the search results. Whenever you interact with a user by messaging or commenting then this is the pic that people see. Generally, if you have a recognizable business logo then you can put a clear and nice image of your business logo as the profile pic. If you think that users may not get much info about your business from your logo then try putting in a good quality picture of the product you mainly sell.

You basically want people to easily recognize your brand. Once you are happy with a particular pic you can upload it. The next important image is the cover image. This is what people will get to see when they land on your page. It needs to be impressive and should clearly convey what your business is to the user. It is a long image so please ensure that it is of high quality and right dimensions. 720 X 315 pixels generally work. Once you have a good one upload it as a cover image. This is the basic setup of your business page. The other steps are just to make it more presentable to people.

  • Creating a username

Rather than sharing a link which people will not relate to you can create a username for your business page and then share it with people. The maximum length allowed for this is 50 characters.

In general, you will use your business name here. To create a username you click on the left menu. There you will find the option to create a page @username. So, create a meaningful username.

  • Enter More Business Details

The purpose of a Facebook business page is to let people know what they need to know about the business and then either contact you or visit your website or store. For that to happen you have to provide a description of your business. Click ok edit page info and add the description of your business under the description section. Put in all the details that you think that people should know like what the brand sells etc. The description needs to be crisp as it is only around 255 characters. But that many characters are enough to convey important information to your target audience.

You will also get to add more categories besides the one that you already added during the page creation. Other info that can be added here is contact details, location, opening and closing hours, etc. For a detailed description of your page, you have to add a story. For this, you have to access the left menu again and click on see more and then about. Here you will find our story option. Click on it. In this section, you will be able to add more details about your business. Don’t shy away. Tell people what your brand is all about and how it came to be and what are your values, goals, and missions.

  • Creating Page Post

Page posts are quite important. After skimming through your business info people will likely end up surfing your page posts. So, before sharing your page make sure you have a few contents that you can post via your business page. This can be content about your product or brand or something relevant to your brand. Generally, most business pages will choose to post a nice image or video of the product they are selling. Try not to skip this step as it will make your page feel more professional and legit.

Now, all that’s left is to publish this page and invite users to visit the page. Keep monitoring all the relevant stats of the page to see how many users are visiting your page and engaging with your posts. Let’s now move on to other sections in this guide to learn more about Facebook’s marketing strategy.

Advertisement
free widgets for website

How to Get More Engagement on Facebook

The ultimate goal of any kind of social media marketing is to grow your business by getting more customers and making more sales. To achieve this on social media you have to first get noticed by people and then create compelling content so that they would want to engage with it by liking commenting or replying.

The more people engage with your posts the more is the chance of lead generation and possibly conversions. In this section of the guide, we will be discussing how to get more engagement on Facebook. So, if you are looking for ways to improve the number of likes and comments you get on your posts then read on.

  • Post Regularly and Consistently

One of the things you should do if you are looking to gain more exposure and increase engagement on your posts is to start posting regularly and consistently. It should be quite frequent as well. This does not mean that you will just bombard posts after posts. But try to follow a set routine.

For example, you can choose to post three times (morning, evening, and night) of the day depending on when your audience is likely to be active or when you will receive the lesser competition. Many companies try to post throughout the day while others try to post at specific times. You may have to do a little bit of research or perform trial and error to figure out what schedule is most effective for you. This may change over time as your page grows.

  • No Drop in Quality

There shouldn’t be any drop in the quality of the content. It can sometimes be difficult to maintain the quality of your posts when you are trying to post multiple times a day. But you cannot compromise on the quality of the post. This is because even if you post multiple times and a lot of people get to see the posts they will not engage with it if it is shabbily done.

Try to keep up with the quality of the posts as otherwise people will get used to you not posting good stuff and may end straight up ignoring your posts or not following your page anymore.

  • Post More Videos

Earlier, social media platforms weren’t too good when it came to displaying videos to people. But nowadays, everything is really optimized and people love to watch nice videos on social media platforms. Today, you will find that more people like to engage with video content and enjoy watching such posts. So, it is likely you will capture the attention of your audience with video posts. But it shouldn’t be some boring text-based promotion of your product as people will ignore it.

Come up with interesting ideas to engage people. For example, people love to watch short videos where they learn something. It can be a short recipe, an animal fact, a life hack, etc. So, if you can somehow find a way to create videos that provide all this while at the same time being quite relevant to your brand you will start getting more eyes on your posts and more people will engage with it.

Advertisement
free widgets for website
  • Research Your Audience

One thing that you definitely should not skip is to research who your target audience is. You need to know which age group they belong to, what their geographical location is, what their gender is, are employed/unemployed, etc. The more you know the better. This will help you find out which demographic the majority of your target audience belongs to.

Once you know this you can tailor the content specific to their taste and thus, you will get more engagement from them. You can use Facebook’s analytics tool to conduct this research or go to any third-party website or company to enlist their help.

  • Know When to Post

We touched on this on the first point but let’s elaborate on it here. If you want to maximize engagement on your posts you have to find out an optimal time to post. Now, there are different researches and stats for this that you can check out. Many of the stats have changed after the Pandemic as most people started working from home and the life dynamic changed for many. In general, weekdays show high engagement before evening and it slowly trails off as the day comes to a close.

Weekends get lesser engagement. But after the pandemic, it has been seen that there is good engagement in the evening and towards night as well and there is some engagement during weekends too. We suggest you look at the research done by Hootsuite or HubSpot on this. They go into a lot of detail and talk about the best time to post for different industries as well. Though you may be tempted to post at a time when the engagement is high you need to remember that other companies will be doing the same so the competition will be high.

See also  Why Apple's Privacy Changes Hurt Snap and Facebook but Benefited Google - Wall Street Journal

If you post at off hours then you may not get much competition but fewer people will engage. It is all about hitting that sweet spot. For this, you have to use the trial and error method. Post during different times of the day and figure out what time works best for you and stick to it so that people get used to your posts at a particular time.

  • Build Content Around Your Audience

This is another good thing to implement if you are looking to engage more people with your posts. Social media is about people connecting with each other and sharing stuff. It was initially not intended to be a marketplace. Today, it has become a successful one. But still, the core values of the platforms remain so people tend to gravitate towards brands that feel more personal or sort of human. Posting constantly about your product or service can sort of make your business look too impersonal which may work against you when it comes to social media marketing.

So, once in a while try posting something related to your audience. Maybe share their story about how your product or service has affected their lives. Ask them to post it and then you share it on your page. You can also do a q&a session where you answer their questions about your business. Other humanizing post ideas can be posting about your workers or posting behind the scene style videos. You can also upload feedback-style content where you ask people to comment or like based on their opinions. You can get inspiration from the posts of your competitors.

  • Contests and Giveaways

Another good way to increase engagement on Facebook and most other social media platforms is to run contests and Giveaways. Everyone likes to get free stuff. Even though most people may not win something they will still engage with your post since there is some hope of getting something for free.

You can run contests for discounts on your products or directly provide the product to the winner for free. Giveaways are simple and easy to do.  You just ask people to comment on your post and then randomly select a name using a bot. The contests are a bit different. Try to come up with creative ideas for contests. An interesting game or quiz or maybe something entirely unique. Something that your audience will enjoy.

Advertisement
free widgets for website
  • Feedback and Tweaking

Always try to measure the performance of your posts and see how well it is fulfilling your goals. If it isn’t able to do what it is intended to then you can look for what you can improve and then implement that. If you are in it alone without many experts then you need to know that marketing is all about planning, feedback, and optimization. You need to keep doing trial and error until you hit the right strategy for optimum growth.

So, those were some of the tips on how to increase engagement on Facebook. We suggest you go through them and use the one that you think your strategy is lacking. Better outcomes come when you combine a bunch of them.

Creating a Marketing Strategy for Facebook

Most things benefit if they start with a plan. Of course, being random and spontaneous can sometimes work in your favor but when it comes to marketing planning is the way to go. It sets you up nicely to measure your success and keeps you ready in case things don’t work out and you need to change things. Having a Facebook marketing strategy can help a lot. It will organize things for you and you can be more effective and efficient at whatever you do.

You will not waste much time and will be able to understand what tasks are more effective to achieve your goal and how much time and effort you should put into different tasks. Due to the importance of a marketing strategy when it comes to Facebook marketing we decided to discuss that in this section of the guide. So, if you are ready to get some idea about how to strategize for Facebook marketing read on.

  • Figure Out Your Audience

This is the first step that you need to perform when formulating a marketing strategy for Facebook. You need to sit down and start researching who your target audience on Facebook is. Without this, you may not be able to effectively implement your strategy. You need to know who this strategy is going to target. Your product or service will be the first clue obviously.

When you were already creating your product or service you had a target audience in mind. Chances are the results will be similar on Facebook. But you never know who might be interested. So, after you have built your page and invited people, and uploaded a bunch of posts you need to use the audience insight tool that Facebook provides to find out who is watching your videos and engaging with your content.

Using this tool you will be able to figure out the age group of your audience, the geographical location, do they use a mobile device, or a desktop, at what time they browse Facebook, etc. These insights can be quite helpful in tailoring your content to suit the needs of your major target audience. You can use these audience insights in different strategies that you create to promote different products.

Advertisement
free widgets for website
  • Jot Down the Goals and Objectives

This is another very important step that you should never skip. You need to clearly set the goals and objectives for the strategy. What do you want to achieve? Why did you begin formulating a Facebook marketing strategy? Did you need more sales? These are some of the questions that you need to have the answer to.

Let’s say you are going to launch a new product and you want people to add it to their wishlist or pre-order the product. So, your goal is to generate as many pre-ordered as possible. In general, businesses want a good marketing strategy because they want to generate more leads, make more sales, get more conversions, get more exposure, etc. Select a metric to measure the success of your strategy.

For example, if you wanted to increase the website traffic from Facebook then you need to measure the number of website visits that you get after implementing the strategy. This can help you understand how well the strategy is performing and whether or not you need to tweak a thing or two. Without goals and objectives, you will have no tangible way of measuring how good your strategy is.

  • Decide on Your Content

Yes! You need to plan ahead when it comes to posting content on your Facebook business page. This way when you actually are deciding on what to post you already know the type of content you are going to post and you just need to figure out the specifics. Deciding ahead on the type of content people will gain from your business page will ensure that your brand remains consistent with its posting. If you keep posting a bunch of random stuff without any clear plan people will not be able to relate you to your content and thus, you will not be recognizable.

Though content planning generally differs from brands to brands and industries to industries there are a couple of things that you need to keep in mind. One of the important things that one should remember is that the bulk of the content should be targeted towards the audience. We touched on this point in the previous section under the ‘Build Your Content Around Your Audience’ point. Social media has become a marketplace in recent years but people still do not want to be constantly sold stuff on these platforms. They want to relax. So, your content should be created keeping that point in mind.

Try to create entertaining and educating content. People like to learn random things on the internet. Use that to your advantage and post content relevant to your brand that can be entertaining, informative, or educational. You should, of course, promote your products and services but that should not be what the majority of your content should be about. 6 to 7 posts out of 10 should be entertainment and leisurely stuff. Rest you can keep for promotion.

  • Make Your Page Better, Engaging

Look, the above tips only work if people are actually seeing your content. They won’t be able to do that if you do not follow your page or at the very least go there once. This is why you need to plan on how you can start getting more people to your page. Remember the page username. Well, you can share that link on multiple platforms.

See also  Biden allies urge Facebook to review spread of election fraud claims

If one of the platforms already has some following then chances are some of those users will check out your Facebook page. Try to put the link everywhere that you are active online on your website, LinkedIn, Glassdoor etc. Next, you need to make your page engaging. We already talked about business page creation in this guide so do check it out. You need to provide all the info in detail and then provide a really good cover image that catches the eye of the person visiting your page while communicating the essence of your page.

Advertisement
free widgets for website

So, take some time to optimize your page. Show it to people. Get some feedback. Do you think that you would want to follow this page or look more into it after you land on it? Also, you can always keep tweaking stuff till it works. But remember it is very important that your business page looks good and is engaging as otherwise people will not follow your page and thus no one will see your content.

  • Get Used to Using Tools

Facebook is a big platform that provides a bunch of different tools to people looking to use the platform as a marketplace. It provides audience insights tools, analytics tools, business managers, Facebook groups, chatbots etc. All these tools if used correctly along with your strategy can work really well to support your strategy and make it more effective.

For example, a Facebook group is a feature that you can use to create a community around your brand. You can be a part of groups to promote your brand as well as create your own group to build a community of people interested in your brand. The insights and analytics tools are helpful in measuring the performance of your Facebook marketing. Chatbots and business managers are tools provided by Facebook so that it is easier for businesses to effectively manage their business and easily interact with the audience.

  • Facebook Paid Ads

In the last section of the guide, we decided to give you an idea about Facebook paid ads. If you have some sort of budget allocated to your online marketing budget you can try out paid ads for Facebook. It is a good way to reach more people and thus get more people to your page, generate more leads, make more sales, etc. Organic reach is nice as you get to learn a lot and you do not have to spend any money. But it is slow.

If you are starting out then it can be difficult to gain a lot of reaches as pages that have fewer than 10k followers have a very low reach. This is because Facebook tries to show people posts from their friends, family, and relatives. Using paid ads can sometimes greatly help increase the number of people that get exposed to your page. If you still think that you want to go the organic way you can go there. But if you are looking to mix the organic and paid method then this section can help you out. If you want to get a bit of an idea about Facebook paid ads then this is the section for you.

Creating ads on Facebook is very simple. You just need to have a clear idea about what your goals are and who you want to target. Having this information beforehand can help in crafting a good ad. There are 5 steps to creating an ad on Facebook namely Creating a campaign, ads design, audience creation, budget and bidding, and publishing. You can use this to gain more traffic to your website, generate more leads, sell products, create brand awareness, etc.

Sometimes paid ads can be very effective in increasing exposure. But if you don’t want to pay then you can skip that section. We hope you found enough material to be able to start formulating your strategy to promote your brand on Facebook.

Advertisement
free widgets for website

Facebook Analytics

Analytics is an important part of any strategy. You may have understood this by now. We have been constantly talking about measuring performance and using it to optimize your strategy further analytics is a tangible way to check how well your strategy is performing. Without the right tools and analytics, it will be really hard to pinpoint exactly what is working and what’s not. You have to rely on guesswork which may not give you accurate feedback and thus, you will not be able to optimize your strategy which will lead it to underperform.

There are many third-party tools that one can use to get meaningful insights into their audience and the performance of their paid ads or posts. We will be focusing on the tool that Facebook itself provides. This is the Facebook insights tool. We saw one usage of it previously where we found out how to use it to determine who your target audience is. Let’s now take a look at what page insights is.

Facebook Page Insight

If you want to access the insights tool for your business page you need to go to the top menu of the page. There you will find the insights option. As soon as you click on it you will be taken to an overview page. Now, what’s an overview page? This is a page that will provide the last week’s metrics for the most important activities on your page. It sort of summarizes how well your page has been doing in the last 7 days. You can get information like – actions on page, page views, page previews, page likes, post reach, recommendations, etc.

On the left-hand side of this overview page, you will see multiple options. These are the ones which will give you more idea about the performance of your business page. Let’s take a look at a few of them.

  • Followers

The followers metric shows you how many page followers you have gained and lost. This will be displayed in the form of a graph on a day-to-day basis. You will be able to see your gain and loss for each day.

  • Likes

This is another important metric to keep an eye on. How many people are liking your page or unliking it. If the latter is more then probably you are doing something wrong. You can click on the net likes option to know what is the net loss or gain of likes for that particular day. On the right-hand side, you will be able to see more metrics.

Like paid likes, organic likes, etc. Each of these will have a different colored graph and they will be superimposed. You can also see the average net likes that you generally get on a daily basis.

Advertisement
free widgets for website
  • Reach

Reach is another important aspect of Facebook marketing. You need to know how many people saw your posts and how many people were able to discover your page. The more engagement that happens on your page and posts the more are the chances of your page reaching people’s news feed. This is how you get more reach and exposure.

Similar to the likes section here you will be able to see both organic and paid likes. You can click on the spikes on specific days and see the content and how people engaged with it

  • Page Views

Pageviews detail the number of people that have visited your page. You also get to know where people go after they visit your page.

If you have provided the link to your page at different platforms and websites then you can click on top sources to see where the traffic is coming from. So, it is quite a useful tool.

  • Posts

This is one of the most useful metrics. Here you will find out how many of your page fans are online. This can help you understand when you can expect most people to see your posts and plan your schedule accordingly. Here, you will also see all the posts that you have uploaded so far along with the core metrics of this post.

This can help you figure out what posts are working in your favor and gaining you more engagement. You can also change the displayed metrics as you want using the options provided on the upper right corner of the table. Click on the arrow to get more options.

Conclusion

So, that was our guide on Facebook marketing. Our aim with it was to push you in the right direction and give you an idea of how to get started with Facebook marketing.

This all sounds overwhelming but once you start understanding the nuances of it all things will become easier. We hope you got a lot of info that will be helpful to you.

Advertisement
free widgets for website

Published April 11th, 2021

Read More

Continue Reading
Advertisement free widgets for website
Click to comment

Leave a Reply

Your email address will not be published.

FACEBOOK

Meet the Developers – Linux Kernel Team (Martin Lau)

Published

on

By

meet-the-developers-–-linux-kernel-team-(martin-lau)

For today’s interview, we have Martin Lau, a software engineer on the Kernel team at Meta. He works on the BPF (Berkeley Packet Filter) and Kernel Networking development.

This series highlights Meta Software Engineers who contribute to the Linux kernel. The Meta Linux Kernel team works with the broader Linux community to add new features to the kernel and makes sure that the kernel works well in Meta production data centers. Engineers on the team work with peers in the industry to make the kernel better for Meta’s workloads and to make Linux better for everyone.

Tell us about yourself and what your typical day looks like as a kernel developer at Meta.

My name is Martin KaFai Lau. I have been with Meta for 9 and a half years. I joined the Meta Kernel team 6 years ago. I am focusing on BPF and networking development. Before that, I was on the Meta Traffic team doing HTTP, TLS and CDN work.

My typical day involves reviewing patches in the mailing list, supporting Meta use cases in production, exploring ideas with other networking teams and writing patches for upstream.

What have you been excited about or incredibly proud of lately?

Works that make kernel networking stack extensible by BPF. It also excites me to work on stackable workloads that need to impose bandwidth limitations per task, explore One-Way-Delay measurement with BPF and speed up a service start-up time from more than a minute down to 6 seconds.

Advertisement
free widgets for website

Is there something especially exciting about being a Kernel developer at a company like Meta?

Scale. Being able to solve problems in Meta’s production scale is very exciting. Kernel is the core piece used by all services, and it is the core interface between a computer’s hardware and its processes. Improvement in kernel will have a positive effect on all of them.

See also  TikToker divorces husband after noticing sketchy detail in Facebook photo of him

Scale is also about the number of internal users that have a lot of production experience, and each of them could have a diverge usage. It is so much faster to get feedback from different teams, and they can explain if something will work well in the real world or not. Their feedback also leads to new kernel development.

My coworkers are maintainers in different kernel subsystems that I am not familiar with. This is a great learning experience that is very valuable in Meta.

Tell us a bit about the topic you presented at the Linux Plumbers Conference (LPC) this year.

In the LPC presentation, I gave an overview of the BPF networking hooks in the kernel and how Meta uses them, the surprises I usually hear about from our internal users and what could be addressed in the future.

Over the years, BPF has grown considerably, so it can sometimes be difficult to navigate how BPF should be used in the networking stack. You can explore some of the resources from the talk on the event page “Overview of the BPF networking hooks and user experience in Meta.”

Advertisement
free widgets for website

What are some of the misconceptions about kernel or OSS development that you have encountered in your career?

My previous life was user space only. I usually could quickly understand the big picture of the whole piece I was working on. I thought that would be hard in the kernel because the code base is large. More importantly, it is also tough to get help from upstream people.

See also  5 things to know for October 4: Congress, Covid-19, Facebook, Brazil, oil spill - ABC17NEWS

I spent time reading and observing the mailing list and paid attention to how people work on the mailing list. It is impossible to get a grip on everything in the kernel. I shrink the scope, focus on one piece and fix something to gain credibility in the upstream. Then, I repeat the process to expand my knowledge space.

What resources are helpful in getting started in kernel development, and where can people follow your work?

The Linux kernel mailing list. Spend time reading the threads that you are interested in. Understand the concern and interests that the stakeholders usually have. Start with something small that solves a real production problem.

I am usually active in the BPF mailing list.

To learn more about Meta Open Source, visit our open source site, subscribe to our YouTube channel, or follow us on Twitter, Facebook and LinkedIn.

Advertisement
free widgets for website

Image credit: Larry Ewing (lewing@isc.tamu.edu) and The GIMP for the original design of Tux the penguin.

First seen at developers.facebook.com

Continue Reading

FACEBOOK

Upcoming Restriction Period for US ads about social issues, elections, or politics

Published

on

By

upcoming-restriction-period-for-us-ads-about-social-issues,-elections,-or-politics

In recent years, Meta has developed a comprehensive approach to protecting elections on our technologies. These efforts continue in advance of the US 2022 Midterms, which you can read more about in our Newsroom.

Implementing a restriction period for ads about social issues, elections or politics in the US

Consistent with our approach during the US 2020 General Election, we are introducing a restriction period for ads about social issues, elections or politics in the US. The restriction period will run from 12:01 AM PT on Tuesday, November 1, 2022 through 11:59 PM PT on Tuesday, November 8, 2022.

We are putting this restriction period in place again because we found that the restriction period achieves the right balance of giving campaigns a voice while providing additional time for scrutiny of issue, electoral, and political ads in the Ad Library. We are sharing the requirements and key dates ahead of time, so advertisers are able to prepare their campaigns in the months and weeks ahead.

What to know about the ad restriction period in the US

We will not allow any new ads about social issues, elections or politics in the US from 12:01 AM PT on Tuesday, November 1, 2022 through 11:59 PM PT on Tuesday, November 8, 2022.

In order to run ads about social issues, elections or politics in the US during the restriction period, the ads must be created with a valid disclaimer and have delivered an impression prior to 12:01 AM PT on Tuesday, November 1, 2022, but with limited editing capabilities.

Advertisement
free widgets for website

What advertisers can do during the restriction period for eligible ads:

  • Edit bid amount, budget amount and scheduled end date
  • Pause and unpause eligible ads that have already served at least 1 impression with a valid disclaimer prior to the restriction period going into effect
See also  Facebook’s lead EU privacy supervisor hit with corruption complaint

What advertisers cannot do during the restriction period for eligible ads, includes but is not limited to:

  • Editing certain aspects of eligible ads, such as ad creative (including ad copy, image/video assets, website URL)
  • Editing targeting, placement, optimization or campaign objective
  • Removing or adding a disclaimer
  • Copy, duplicating or boosting ads

See the Help Center for detailed requirements of what is or isn’t allowed during the restriction period.

Planning ahead for key dates

Keep in mind the following dates as you plan your campaign to avoid delays or disapprovals that may prevent your ads from running during the restriction period:

  • By Tuesday, October 18, 2022: Complete the ad authorization process to get authorized to run ads about social issues, elections or politics, which includes setting up an approved disclaimer for your ads.

  • By Tuesday, October 25, 2022: Submit your issue, electoral or political ads in order to best ensure that your ads are live and have delivered at least 1 impression with a valid disclaimer before the restriction period begins.
    • Please ensure that you add your approved disclaimer to these ads by choosing ISSUES_ELECTIONS_POLITICS in the special_ad_categories field. You will not be able to add a disclaimer after 12:01 AM PT on Tuesday, November 1, 2022.

  • Between Tuesday, November 1, 2022 and Tuesday, November 8, 2022: The ad restriction period will be in effect. We will not allow any new ads to run about social issues, elections or politics in the US starting 12:01 AM PT on Tuesday, November 1 through 11:59 PM PT on Tuesday, November 8, 2022.
  • At 12:00 AM PT on Wednesday, November 9, 2022: We will allow new ads about social issues, elections or politics to be published.

As the restriction period approaches, we encourage you to review these ad restriction period best practices to properly prepare ahead of time.

We will continue to provide updates on our approach to elections integrity or on any changes regarding the restriction period via this blog.

Visit the Elections Hub or our FAQ for more advertising resources.

First seen at developers.facebook.com

Advertisement
free widgets for website
Continue Reading

FACEBOOK

Signals in prod: dangers and pitfalls

Published

on

By

signals-in-prod:-dangers-and-pitfalls

In this blog post, Chris Down, a Kernel Engineer at Meta, discusses the pitfalls of using Linux signals in Linux production environments and why developers should avoid using signals whenever possible.

What are Linux Signals?

A signal is an event that Linux systems generate in response to some condition. Signals can be sent by the kernel to a process, by a process to another process, or a process to itself. Upon receipt of a signal, a process may take action.

Signals are a core part of Unix-like operating environments and have existed since more or less the dawn of time. They are the plumbing for many of the core components of the operating system—core dumping, process life cycle management, etc.—and in general, they’ve held up pretty well in the fifty or so years that we have been using them. As such, when somebody suggests that using them for interprocess communication (IPC) is potentially dangerous, one might think these are the ramblings of someone desperate to invent the wheel. However, this article is intended to demonstrate cases where signals have been the cause of production issues and offer some potential mitigations and alternatives.

Signals may appear attractive due to their standardization, wide availability and the fact that they don’t require any additional dependencies outside of what the operating system provides. However, they can be difficult to use safely. Signals make a vast number of assumptions which one must be careful to validate to match their requirements, and if not, one must be careful to configure correctly. In reality, many applications, even widely known ones, do not do so, and may have hard-to-debug incidents in the future as a result.

Let us look into a recent incident that occurred in the Meta production environment, reinforcing the pitfalls of using signals. We’ll go briefly over the history of some signals and how they led us to where we are today, and then we’ll contrast that with our current needs and issues that we’re seeing in production.

Advertisement
free widgets for website

The Incident

First, let’s rewind a bit. The LogDevice team cleaned up their codebase, removing unused code and features. One of the features that was deprecated was a type of log that documents certain operations performed by the service. This feature eventually became redundant, had no consumers and as such was removed. You can see the change here on GitHub. So far, so good.

The next little while after the change passed without much to speak about, production continued ticking on steadily and serving traffic as usual. A few weeks later, a report that service nodes were being lost at a staggering rate was received. It was something to do with the rollout of the new release, but what exactly was wrong was unclear. What was different now that had caused things to fall over?

The team in question narrowed the problem to the code change we mentioned earlier, deprecating these logs. But why? What’s wrong with that code? If you don’t already know the answer, we invite you to look at that diff and try to work out what’s wrong because it’s not immediately obvious, and it’s a mistake anyone could make.

logrotate, Enter the Ring

logrotate is more or less the standard tool for log rotation when using Linux. It’s been around for almost thirty years now, and the concept is simple: manage the life cycle of logs by rotating and vacuuming them.

logrotate doesn’t send any signals by itself, so you won’t find much, if anything, about them in the logrotate main page or its documentation. However, logrotate can take arbitrary commands to execute before or after its rotations. Just as a basic example from the default logrotate configuration in CentOS, you can see this configuration:

Advertisement
free widgets for website
 /var/log/cron /var/log/maillog /var/log/messages /var/log/secure /var/log/spooler {     sharedscripts     postrotate         /bin/kill -HUP `cat /var/run/syslogd.pid 2> /dev/null` 2> /dev/null || true     endscript } 

A bit brittle, but we’ll forgive that and assume that this works as intended. This configuration says that after logrotate rotates any of the files listed, it should send SIGHUP to the pid contained in /var/run/syslogd.pid, which should be that of the running syslogd instance.

This is all well and good for something with a stable public API like syslog, but what about something internal where the implementation of SIGHUP is an internal implementation detail that could change at any time?

A History of Hangups

One of the problems here is that, except for signals which cannot be caught in user space and thus have only one meaning, like SIGKILL and SIGSTOP, the semantic meaning of signals is up to application developers and users to interpret and program. In some cases, the distinction is largely academic, like SIGTERM, which is pretty much universally understood to mean “terminate gracefully as soon as possible.” However, in the case of SIGHUP, the meaning is significantly less clear.

SIGHUP was invented for serial lines and was originally used to indicate that the other end of the connection had dropped the line. Nowadays, we still carry our lineage with us of course, so SIGHUP is still sent for its modern equivalent: where a pseudo or virtual terminal is closed (hence tools like nohup, which mask it).

In the early days of Unix, there was a need to implement daemon reloading. This usually consists at least of configuration/log file reopening without restarting, and signals seemed like a dependency-free way to achieve that. Of course, there was no signal for such a thing, but as these daemons have no controlling terminal, there should be no reason to receive SIGHUP, so it seemed like a convenient signal to piggyback onto without any obvious side effects.

Advertisement
free widgets for website

There is a small hitch with this plan though. The default state for signals is not “ignored,” but signal-specific. So, for example, programs don’t have to configure SIGTERM manually to terminate their application. As long as they don’t set any other signal handler, the kernel just terminates their program for free, without any code needed in user space. Convenient!

What’s not so convenient though, is that SIGHUP also has the default behavior of terminating the program immediately. This works great for the original hangup case, where these applications likely aren’t needed anymore, but is not so great for this new meaning.

This would be fine of course, if we removed all the places which could potentially send SIGHUP to the program. The problem is that in any large, mature codebase, that is difficult. SIGHUP is not like a tightly controlled IPC call for which you can easily grep the codebase for. Signals can come from anywhere, at any time, and there are few checks on their operation (other than the most basic “are you this user or have CAP_KILL“). The bottom line is that it’s hard to determine where signals could come from, but with more explicit IPC, we would know that this signal doesn’t mean anything to us and should be ignored.

See also  Biden allies urge Facebook to review spread of election fraud claims

From Hangup to Hazard

By now, I suppose you may have started to guess what happened. A LogDevice release started one fateful afternoon containing the aforementioned code change. At first, nothing had gone awry, but at midnight the next day, everything mysteriously started falling over. The reason is the following stanza in the machine’s logrotate configuration, which sends a now unhandled (and therefore fatal) SIGHUP to the logdevice daemon:

 /var/log/logdevice/audit.log {   daily   # [...]   postrotate     pkill -HUP logdeviced   endscript } 

Missing just one short stanza of a logrotate configuration is incredibly easy and common when removing a large feature. Unfortunately, it’s also hard to be certain that every last vestige of its existence was removed at once. Even in cases that are easier to validate than this, it’s common to mistakenly leave remnants when doing code cleanup. Still, usually, it’s without any destructive consequences, that is, the remaining detritus is just dead or no-op code.

Advertisement
free widgets for website

Conceptually, the incident itself and its resolution are simple: don’t send SIGHUP, and spread LogDevice actions out more over time (that is, don’t run this at midnight on the dot). However, it’s not just this one incident’s nuances that we should focus on here. This incident, more than anything, has to serve as a platform to discourage the use of signals in production for anything other than the most basic, essential cases.

The Dangers of Signals

What Signals are Good For

First, using signals as a mechanism to affect changes in the process state of the operating system is well founded. This includes signals like SIGKILL, which are impossible to install a signal handler for and does exactly what you would expect, and the kernel-default behavior of SIGABRT, SIGTERM, SIGINT, SIGSEGV, and SIGQUIT and the like, which are generally well understood by users and programmers.

What these signals all have in common is that once you’ve received them, they’re all progressing towards a terminal end state within the kernel itself. That is, no more user space instructions will be executed once you get a SIGKILL or SIGTERM with no user space signal handler.

A terminal end state is important because it usually means you’re working towards decreasing the complexity of the stack and code currently being executed. Other desired states often result in the complexity actually becoming higher and harder to reason about as concurrency and code flow become more muddled.

Dangerous Default Behavior

You may notice that we didn’t mention some other signals that also terminate by default. Here’s a list of all of the standard signals that terminate by default (excluding core dump signals like SIGABRT or SIGSEGV, since they’re all sensible):

Advertisement
free widgets for website
  • SIGALRM
  • SIGEMT
  • SIGHUP
  • SIGINT
  • SIGIO
  • SIGKILL
  • SIGLOST
  • SIGPIPE
  • SIGPOLL
  • SIGPROF
  • SIGPWR
  • SIGSTKFLT
  • SIGTERM
  • SIGUSR1
  • SIGUSR2
  • SIGVTALRM

At first glance, these may seem reasonable, but here are a few outliers:

  • SIGHUP: If this was used only as it was originally intended, defaulting to terminate would be sensible. With the current mixed usage meaning “reopen files,” this is dangerous.
  • SIGPOLL and SIGPROF: These are in the bucket of “these should be handled internally by some standard function rather than your program.” However, while probably harmless, the default behavior to terminate still seems nonideal.
  • SIGUSR1 and SIGUSR2: These are “user-defined signals” that you can ostensibly use however you like. But because these are terminal by default, if you implement USR1 for some specific need and later don’t need that, you can’t just safely remove the code. You have to consciously think to explicitly ignore the signal. That’s really not going to be obvious even to every experienced programmer.

So that’s almost one-third of terminal signals, which are at best questionable and, at worst, actively dangerous as a program’s needs change. Worse still, even the supposedly “user-defined” signals are a disaster waiting to happen when someone forgets to explicitly SIG_IGN it. Even an innocuous SIGUSR1 or SIGPOLL may cause incidents.

This is not simply a question of familiarity. No matter how well you know how signals work, it’s still extremely hard to write signal-correct code the first time around because, despite their appearance, signals are far more complex than they seem.

Code flow, Concurrency, and the Myth of SA_RESTART

Programmers generally do not spend their entire day thinking about the inner workings of signals. This means that when it comes to actually implementing signal handling, they often subtly do the wrong thing.

I’m not even talking about the “trivial” cases, like safety in a signal handling function, which is mostly solved by only bumping a sig_atomic_t, or using C++’s atomic signal fence stuff. No, that’s mostly easily searchable and memorable as a pitfall by anyone after their first time through signal hell. What’s a lot harder is reasoning about the code flow of the nominal portions of a complex program when it receives a signal. Doing so requires either constantly and explicitly thinking about signals at every part of the application life cycle (hey, what about EINTR, is SA_RESTART enough here? What flow should we go into if this terminates prematurely? I now have a concurrent program, what are the implications of that?), or setting up a sigprocmask or pthread_setmask for some part of your application life cycle and praying that the code flow never changes (which is certainly not a good guess in an atmosphere of fast-paced development). signalfd or running sigwaitinfo in a dedicated thread can help somewhat here, but both of these have enough edge cases and usability concerns to make them hard to recommend.

We like to believe that most experienced programmers know by now that even a facetious example of correctly writing thread-safe code is very hard. Well, if you thought correctly writing thread-safe code was hard, signals are significantly harder. Signal handlers must only rely on strictly lock-free code with atomic data structures, respectively, because the main flow of execution is suspended and we don’t know what locks it’s holding, and because the main flow of execution could be performing non-atomic operations. They must also be fully reentrant, that is, they must be able to nest within themselves since signal handlers can overlap if a signal is sent multiple times (or even with one signal, with SA_NODEFER). That’s one of the reasons why you can’t use functions like printf or malloc in a signal handler because they rely on global mutexes for synchronization. If you were holding that lock when the signal was received and then called a function requiring that lock again, your application would end up deadlocked. This is really, really hard to reason about. That’s why many people simply write something like the following as their signal handling:

 static volatile sig_atomic_t received_sighup;   static void sighup(int sig __attribute__((unused))) { received_sighup = 1; }  static int configure_signal_handlers(void) {   return sigaction(     SIGHUP,     &(const struct sigaction){.sa_handler = sighup, .sa_flags = SA_RESTART},     NULL); }  int main(int argc, char *argv[]) {   if (configure_signal_handlers()) {        /* failed to set handlers */   }    /* usual program flow */    if (received_sighup) {     /* reload */     received_sighup = 0;   }    /* usual program flow */ }  

The problem is that, while this, signalfd, or other attempts at async signal handling might look fairly simple and robust, it ignores the fact that the point of interruption is just as important as the actions performed after receiving the signal. For example, suppose your user space code is doing I/O or changing the metadata of objects that come from the kernel (like inodes or FDs). In this case, you’re probably actually in a kernel space stack at the time of interruption. For example, here’s how a thread might look when it’s trying to close a file descriptor:

Advertisement
free widgets for website
# cat /proc/2965230/stack  [<0>] schedule+0x43/0xd0  [<0>] io_schedule+0x12/0x40  [<0>] wait_on_page_bit+0x139/0x230  [<0>] filemap_write_and_wait+0x5a/0x90  [<0>] filp_close+0x32/0x70  [<0>] __x64_sys_close+0x1e/0x50  [<0>] do_syscall_64+0x4e/0x140  [<0>] entry_SYSCALL_64_after_hwframe+0x44/0xa9

Here, __x64_sys_close is the x86_64 variant of the close system call, which closes a file descriptor. At this point in its execution, we’re waiting for the backing storage to be updated (that’s this wait_on_page_bit). Since I/O work is usually several orders of magnitude slower than other operations, schedule here is a way of voluntarily hinting to the kernel’s CPU scheduler that we are about to perform a high-latency operation (like disk or network I/O) and that it should consider finding another process to schedule instead of the current process for now. This is good, as it allows us to signal to the kernel that it is a good idea to go ahead and pick a process that will actually make use of the CPU instead of wasting time on one which can’t continue until it’s finished waiting for a response from something that may take a while.

Imagine that we send a signal to the process we were running. The signal that we have sent has a user space handler in the receiving thread, so we’ll resume in user space. One of the many ways this race can end up is that the kernel will try to come out of schedule, further unwind the stack and eventually return an errno of ESYSRESTART or EINTR to user space to indicate that we were interrupted. But how far did we get in closing it? What’s the state of the file descriptor now?

Now that we’ve returned to user space, we’ll run the signal handler. When the signal handler exits, we’ll propagate the error to the user space libc’s close wrapper, and then to the application, which, in theory, can do something about the situation encountered. We say “in theory” because it’s really hard to know what to do about many of these situations with signals, and many services in production do not handle the edge cases here very well. That might be fine in some applications where data integrity isn’t that important. However, in production applications that do care about data consistency and integrity, this presents a significant problem: the kernel doesn’t expose any granular way to understand how far it got, what it achieved and didn’t and what we should actually do about the situation. Even worse, if close returns with EINTR, the state of the file descriptor is now unspecified:

“If close() is interrupted by a signal [...] the state of [the file descriptor] is unspecified.”

Good luck trying to reason about how to handle that safely and securely in your application. In general, handling EINTR even for well-behaved syscalls is complicated. There are plenty of subtle issues forming a large part of the reason why SA_RESTART is not enough. Not all system calls are restartable, and expecting every single one of your application’s developers to understand and mitigate the deep nuances of getting a signal for every single syscall at every single call site is asking for outages. From man 7 signal:

Advertisement
free widgets for website

“The following interfaces are never restarted after being interrupted by a signal handler, regardless of the use of SA_RESTART; they always fail with the error EINTR [...]”

Likewise, using a sigprocmask and expecting code flow to remain static is asking for trouble as developers do not typically spend their lives thinking about the bounds of signal handling or how to produce or preserve signal-correct code. The same goes for handling signals in a dedicated thread with sigwaitinfo, which can easily end up with GDB and similar tools being unable to debug the process. Subtly wrong code flows or error handling can result in bugs, crashes, difficult to debug corruptions, deadlocks and many more issues that will send you running straight into the warm embrace of your preferred incident management tool.

High Complexity in Multithreaded Environments

If you thought all this talk of concurrency, reentrancy and atomicity was bad enough, throwing multithreading into the mix makes things even more complicated. This is especially important when considering the fact that many complex applications run separate threads implicitly, for example, as part of jemalloc, GLib, or similar. Some of these libraries even install signal handlers themselves, opening a whole other can of worms.

Overall, man 7 signal has this to say on the matter:

“A signal may be generated (and thus pending) for a process as a whole (e.g., when sent using kill(2)) or for a specific thread [...] If more than one of the threads has the signal unblocked, then the kernel chooses an arbitrary thread to which to deliver the signal.”

Advertisement
free widgets for website

More succinctly, “for most signals, the kernel sends the signal to any thread that doesn’t have that signal blocked with sigprocmask“. SIGSEGV, SIGILL and the like resemble traps, and have the signal explicitly directed at the offending thread. However, despite what one might think, most signals cannot be explicitly sent to a single thread in a thread group, even with tgkill or pthread_kill.

This means that you can’t trivially change overall signal handling characteristics as soon as you have a set of threads. If a service needs to do periodic signal blocking with sigprocmask in the main thread, you need to somehow communicate to other threads externally about how they should handle that. Otherwise, the signal may be swallowed by another thread, never to be seen again. Of course, you can block signals in child threads to avoid this, but if they need to do their own signal handling, even for primitive things like waitpid, it will end up making things complex.

Just as with everything else here, these aren’t technically insurmountable problems. However, one would be negligent in ignoring the fact that the complexity of synchronization required to make this work correctly is burdensome and lays the groundwork for bugs, confusion and worse.

Lack of Definition and Communication of Success or Failure

Signals are propagated asynchronously in the kernel. The kill syscall returns as soon as the pending signal is recorded for the process or thread’s task_struct in question. Thus, there’s no guarantee of timely delivery, even if the signal isn’t blocked.

Even if there is timely delivery of the signal, there’s no way to communicate back to the signal issuer what the status of their request for action is. As such, any meaningful action should not be delivered by signals, since they only implement fire-and-forget with no real mechanism to report the success or failure of delivery and subsequent actions. As we’ve seen above, even seemingly innocuous signals can be dangerous when they are not configured in user space.

Advertisement
free widgets for website

Anyone using Linux for long enough has undoubtedly run into a case where they want to kill some process but find that the process is unresponsive even to supposedly always fatal signals like SIGKILL. The problem is that misleadingly, kill(1)’s purpose isn’t to kill processes, but just to queue a request to the kernel (with no indication about when it will be serviced) that someone has requested some action to be taken.

The kill syscall’s job is to mark the signal as pending in the kernel’s task metadata, which it does successfully even when a SIGKILL task doesn’t die. In the case of SIGKILL in particular, the kernel guarantees that no more user mode instructions will be executed, but we may still have to execute instructions in kernel mode to complete actions that otherwise may result in data corruption or to release resources. For this reason, we still succeed even if the state is D (uninterruptible sleep). Kill itself doesn’t fail unless you provided an invalid signal, you don’t have permission to send that signal or the pid that you requested to send a signal to does not exist and is thus not useful to reliably propagate non-terminal states to applications.

In Conclusion

  • Signals are fine for terminal state handled purely in-kernel with no user space handler. For signals that you actually would like to immediately kill your program, leave those signals alone for the kernel to handle. This also means that the kernel may be able to exit early from its work, freeing up your program resources more quickly, whereas a user space IPC request would have to wait for the user space portion to start executing again.
  • A way to avoid getting into trouble handling signals is to not handle them at all. However, for applications handling state processing that must do something about cases like SIGTERM, ideally use a high-level API like folly::AsyncSignalHandler where a number of the warts have already been made more intuitive.

  • Avoid communicating application requests with signals. Use self-managed notifications (like inotify) or user space RPC with a dedicated part of the application life cycle to handle it instead of relying on interrupting the application.
  • Where possible, limit the scope of signals to a subsection of your program or threads with sigprocmask, reducing the amount of code that needs to be regularly scrutinized for signal-correctness. Bear in mind that if code flows or threading strategies change, the mask may not have the effect you intended.
  • At daemon start, mask terminal signals that are not uniformly understood and could be repurposed at some point in your program to avoid falling back to kernel default behavior. My suggestion is the following:
 signal(SIGHUP, SIG_IGN); signal(SIGQUIT, SIG_IGN); signal(SIGUSR1, SIG_IGN); signal(SIGUSR2, SIG_IGN); 

Signal behavior is extremely complicated to reason about even in well-authored programs, and its use presents an unnecessary risk in applications where other alternatives are available. In general, do not use signals for communicating with the user space portion of your program. Instead, either have the program transparently handle events itself (for example, with inotify), or use user space communication that can report back errors to the issuer and is enumerable and demonstrable at compile time, like Thrift, gRPC or similar.

I hope this article has shown you that signals, while they may ostensibly appear simple, are in reality anything but. The aesthetics of simplicity that promote their use as an API for user space software belie a series of implicit design decisions that do not fit most production use cases in the modern era.

Let’s be clear: there are valid use cases for signals. Signals are fine for basic communication with the kernel about a desired process state when there’s no user space component, for example, that a process should be killed. However, it is difficult to write signal-correct code the first time around when signals are expected to be trapped in user space.

Signals may seem attractive due to their standardization, wide availability and lack of dependencies, but they come with a significant number of pitfalls that will only increase concern as your project grows. Hopefully, this article has provided you with some mitigations and alternative strategies that will allow you to still achieve your goals, but in a safer, less subtly complex and more intuitive way.

Advertisement
free widgets for website

To learn more about Meta Open Source, visit our open source site, subscribe to our YouTube channel, or follow us on Twitter, Facebook and LinkedIn.

First seen at developers.facebook.com

Continue Reading

Trending