gui编写线性调频信号

by Sajal Sarwar Sharma

通过萨加尔·萨瓦·夏尔马

是的,我编写了信号量,不,我不是OS开发人员。 (Yes, I coded a Semaphore and no, I am not an OS developer.)

当您在日常编码生活中使用信号量时 (When you might be using semaphores in your daily coding life)

You are sitting in an 8th standard Mathematics classroom reading about Pythagorean Triplets, you are mugging up the Pythagoras Theorem. The famous equation (a * a)+ (b * b) = (c * c) is etched into your mind.

您正坐在第8个标准数学教室里,学习有关勾股三重峰的信息,您正在弄虚毕达哥拉斯定理。 著名的方程(a * a)+(b * b)=(c * c)刻在您的脑海中

Fast forward 10 years — you still recount that day and wondered why in god’s name you were taught that equation, you never really came across anything practical in life that uses this equation and this makes you question our existing education system.

快进10年了–您仍在回顾这一天,并想知道为什么以上帝的名义教您方程式,您在生活中从未真正遇到过使用该方程式的任何实际操作,这使您对我们现有的教育体系提出了质疑。

This is one scenario which makes us wonder whether those educational years of our life were actually worth the effort. A lot of us will agree that a majority of our education isn’t actually helping us in our practical lives.

这是一种使我们怀疑人生中的教育年是否值得付出努力的情况。 我们中的许多人都会同意,我们的大部分教育实际上并没有在我们的实际生活中帮助我们。

I am a Software developer working in a SaaS product, and I come up with such revelations that make me contemplate the stark differences between my theoretical knowledge and practical life. But once in a while, things pop up in the most unusual scenarios and places. They make me wonder whether we ignore and don’t really appreciate what’s actually happening under the hood that drives our everyday lives.

我是从事SaaS产品开发的软件开发人员,而我的启示使我想到了理论知识和实际生活之间的截然不同。 但是有时,在最不寻常的场景和地方会突然出现。 他们让我怀疑我们是否忽略并且不真正欣赏驱动我们日常生活的引擎盖下发生的实际情况。

问题陈述 (The problem statement)

So the story starts when one fine day I was sitting peacefully in my cosy warm corner of the office doing my usual API development. A user ticket popped up that said they had received multiple communications from our service and they were annoyed by it. I double checked the code, but it could not have happened. The cron that runs and sends communication to the end user should only have sent it once (and this cron runs every hour).

因此,故事从美好的一天开始,我和平地坐在办公室舒适温馨的角落里进行我通常的API开发。 弹出一个用户票证,说他们已经从我们的服务中收到了多次通信,并且对此感到恼火。 我仔细检查了代码,但是没有发生。 运行并向最终用户发送通信的cron应该只发送一次( 该cron每小时运行一次 )。

At the same time I received a pagerduty stating that there was a CPU utilisation surge in my cron server. It usually happens once in a while when there are a lot of jobs to be processed by multiple crons. I casually checked the system, and to my surprise I found the issue that was causing all the havoc and those user tickets.

同时,我收到一则pagerduty,指出我的cron服务器中的CPU使用率激增。 当有很多任务要由多个任务处理时,通常会偶尔发生一次。 我随便检查了一下系统,令我惊讶的是,发现了引起所有破坏和那些用户票证的问题。

To my horror, I saw multiple instances of the same communication cron running at the same time, picking the same jobs and sending communications. This explained everything. (This should not have happened — the 1st instance of the cron should have completed its execution before the 2nd instance started running. That’s how cron jobs should work).

令我震惊的是,我看到同一通信cron的多个实例同时运行,选择了相同的作业并发送通信。 这说明了一切。 (这本不应该发生的-cron的第一个实例应在第二个实例开始运行之前完成其执行。这就是cron作业应如何工作的方式)。

That particular day, there was a surge in the number of jobs that the cron should be handling which was causing the cron to keep running way past its usual execution time. This led to the overlap (in other words, it kept running even after an hour, and then the 2nd instance popped up).

那天,cron应该处理的工作数量激增,这导致cron的运行时间超过了正常执行时间。 这导致了重叠(换句话说,即使一个小时后它仍保持运行,然后弹出第二个实例)。

My work was cut out for me: I had to make the execution faster, and never allow multiple instances of the same cron to run simultaneously.

我的工作很辛苦:我必须加快执行速度,并且永远不允许同一cron的多个实例同时运行

解决方案 (The solution)

The first thing that popped up in my mind was to implement Semaphores (finally those Operating System classes came rushing forward in my memory). My professor was right in saying that one fine day I would use this technique to save my own life.

我想到的第一件事是实现信号量 (最终那些操作系统类涌入我的记忆中)。 我的教授说的很对,就是有一天我会使用这种技术来挽救自己的生命。

“Today is that day”, I thought.

我想:“今天是那天”。

So I googled and came upon a lot of useful resources to accomplish my task. I will be writing about my learnings here and how finally I realised that I have actually implemented the Semaphore concept all along.

因此,我搜索了许多有用的资源来完成任务。 我将在这里写我的学习内容,以及最终我如何意识到我实际上一直在实施信号量概念。

第1步 (Step 1)

In your system file directory, create a file named myCronPID.txt which will store the process ID (PID) of the cron running at that particular instance. According to Wikipedia:

在系统文件目录中,创建一个名为myCronPID.txt的文件,该文件将存储在特定实例上运行的cron的进程ID(PID)。 根据维基百科:

In computing, the process identifier (normally referred to as the process ID or PID) is a number used by most operating system kernels — such as those of UNIX, macOS and Microsoft Windows — to uniquely identify an active process.

在计算中, 进程标识符 (通常称为进程IDPID )是大多数操作系统内核(例如UNIX,macOS和Microsoft Windows的内核)使用的数字,用于唯一标识活动进程

第2步 (Step 2)

Find out the process ID (PID) of the cron running. This can be done using the code below (I will be using PHP for reference).

找出正在运行的cron的进程ID(PID)。 这可以使用下面的代码来完成(我将使用PHP作为参考)。

第三步 (Step 3)

For the first time, the file myCronPID.txt will be empty. Store the current PID obtained in step 2 in this file. The next time, while obtaining the PID of the cron currently running (lets say 5678), get the PID from the file myCronPID.txt. The PID obtained from the file (lets say 1234) will be the process ID of the cron instance that was running previously. Check if the PID 1234 is still in the execution/running state. This can be found easily.

第一次,文件myCronPID.txt将为空。 将在步骤2中获得的当前PID存储在该文件中。 下次,在获取当前正在运行的cron的PID时(比如说5678),请从文件myCronPID.txt中获取PID。 从文件中获得的PID(比如说1234)将是先前运行的cron实例的进程ID。 检查PID 1234是否仍处于执行/运行状态。 这很容易找到。

In Linux systems, there’s a folder /proc that has folders for the currently running processes in the system. The name of the folders in this /proc folder are the process IDs. So let’s say if /proc folder contains a folder 1234, then it implies that a process with PID 1234 is in running state. If it doesn’t have such a folder, it implies there’s no process with PID 1234 running at that particular instant.

在Linux系统中,有一个/ proc文件夹,其中包含系统中当前正在运行的进程的文件夹。 / proc文件夹中的文件夹名称是进程ID。 因此,假设/ proc文件夹包含文件夹1234,则表示PID为1234的进程处于运行状态。 如果没有这样的文件夹,则意味着在该特定时刻没有运行PID 1234的进程。

第4步 (Step 4)

In this step, obtain the PID from myCronPID.txt file and check if the process is still running using the code given in Step 3.

在此步骤中,从myCronPID.txt文件获取PID,并使用步骤3中给出的代码检查进程是否仍在运行。

  1. If isProcessRunning returns true, then it implies that the previous running cron instance hasn’t completed its execution. Therefore, the new instance which called the function isProcessRunning should not resume with its execution.

    如果isProcessRunning返回true,则表示先前正在运行的cron实例尚未完成其执行。 因此,调用函数isProcessRunning的新实例不应继续执行。

  2. If isProcessRunning returns false, then it implies the previous cron instance has completed its execution. The new instance which called the function isProcessRunning should resume its execution and put its own process ID in myCronPID.txt

    如果isProcessRunning返回false,则表示先前的cron实例已完成其执行。 名为函数isProcessRunning的新实例应恢复其执行,并将其自己的进程ID放入myCronPID.txt中。

第5步 (Step 5)

Bringing it all together:

整合在一起:

In you’re running cron Instance, just invoke the above class object with its appropriate constructor.

在运行cron Instance时,只需使用适当的构造函数调用上述类对象即可。

$fileName — It will be the name of the file which will store the PID of the cron file.

$ fileName —它是将存储cron文件的PID的文件的名称。

$rootDir — It will be the root directory of your current project.

$ rootDir —这将是当前项目的根目录。

After the invocation, use the methods of the Util in your Cron code as follows:

调用后,按如下所示在Cron代码中使用Util的方法:

This will make sure that there won’t be multiple cron instances of the same job running simultaneously.

这将确保同一作业不会同时运行多个cron实例。

结语 (Wrapping up)

After researching all this and writing the above code, I figured out that I have implemented nothing but Semaphores all along. My OS Professor would have been proud today.

在研究了所有这些并编写了上面的代码之后,我发现除了信号量之外,我什么都没有实现。 我的OS教授今天会为此感到骄傲。

This made me contemplate again: we are just mugging up the concepts. We are not looking into the intricacies of our learnings, but rather we are working on such abstract layers that we don’t take time out to appreciate the beauty of the work that is actually happening under the hood.

这让我再次沉思:我们只是在构思这些概念。 我们不是在研究我们学习的复杂性,而是在这样的抽象层上工作,我们不花时间去欣赏引擎盖下实际发生的工作之美。

Our education system is not always crippled. The way we learn things makes all the difference. Try changing yourself rather than complaining. The world is full of wonders and it’s beautiful.

我们的教育体系并不总是残缺不全。 我们学习事物的方式至关重要。 尝试改变自己而不是抱怨。 世界充满了奇迹,它是美丽的。

PS: I hope you like my article, correct me if I am wrong anywhere.

PS:我希望您喜欢我的文章,如果我在任何地方都做错了,请纠正我。

翻译自: https://www.freecodecamp.org/news/yes-i-coded-a-semaphore-and-no-i-am-not-an-os-developer-c721650e1887/

gui编写线性调频信号

gui编写线性调频信号_是的,我编写了信号量,不,我不是OS开发人员。相关推荐

  1. 软件开发编码规范_如果您只喜欢编码,请不要成为软件开发人员

    软件开发编码规范 If you are starting now or thinking about to start a software development career. Or even i ...

  2. grafana美人鱼_编码美人鱼–我如何从海洋生物学家转到前端开发人员

    grafana美人鱼 I have wanted to share my story for a while, but I didn't know exactly how to start, or e ...

  3. 怎么汇报一周开发工作情况_如何在没有经验的情况下获得第一份开发人员工作

    怎么汇报一周开发工作情况 Whether you've done a coding bootcamp or taught yourself, getting your first developer ...

  4. 秘密潜入2小辣椒_短暂潜入2次,我显然不知道自己作为开发人员正在做什么

    秘密潜入2小辣椒 by Zachary Kuhn 扎卡里·库恩(Zachary Kuhn) 那两次我显然不知道我作为开发人员正在做什么 (Those two times where I clearly ...

  5. 实习一年算工作一年吗?_如何在不到一年的时间里获得开发人员的工作

    实习一年算工作一年吗? by Alexander Kallaway 亚历山大·卡拉威(Alexander Kallaway) 如何在不到一年的时间里获得开发人员的工作 (How to Get a De ...

  6. web前端本科未拿到学位证_您是否需要计算机科学学位才能成为成功的Web开发人员...

    web前端本科未拿到学位证 I graduated from university three years ago with a computer science degree. It was one ...

  7. Java自己文章只能自己修改_文章目录Java代码俯身指南,主要为Java开发人员提供代码复审参考,快捷有效提出修改意见。目的发现代码错误:一个人写的代码可能会有一些思想和设计盲点,多个人尽...

    文章目录 Java代码俯身指南,主要为Java开发人员提供代码复审参考,快捷有效提出修改意见. 目的发现代码错误:一个人写的代码可能会有一些思想和设计盲点,多个人尽早的发现BUG. 统一代码风格:统一 ...

  8. 编写文档_如何通过编写优质文档来使自己的未来快乐

    编写文档 by Gabriele Cimato 加布里埃莱·西马托(Gabriele Cimato) 如何通过编写优质文档来使自己的未来快乐 (How to make your future self ...

  9. 用python编写函数回归分析_用python编写函数的logistic回归系数

    下面是逻辑回归的代码.在from sklearn.linear_model import LogisticRegression from sklearn.model_selection import ...

最新文章

  1. python cv2 hsv数组,len()与 size字段的区别
  2. 谷歌、DeepMind强强联手再发布Dreamer:性能远超“前辈”PlaNet
  3. python生成gif【简明教程】
  4. SQL Server之游标的基础知识
  5. boost::fusion::remove用法的测试程序
  6. phoenix+hbase+Spark整合,Spark处理数据操作phoenix入hbase,Spring Cloud整合phoenix
  7. 初学C#中遇到的问题!
  8. hello python_Python-Hello world!
  9. sql运算符_SQL运算符
  10. deepin系统文本编辑器
  11. 芬兰开放「线上 AI 速成班」,全球网民均可注册【智能快讯】
  12. diamond简介和搭建
  13. STM32从固件库到HAL库
  14. dpdk课程学习之练习笔记四(dns预备)
  15. 使用itextpdf生成pdf
  16. 修改php-fpm监听端口,php-fpm配置详解
  17. 机器学习常用算法归详细纳整理
  18. 【环境搭建】Ubuntu安装vulkan
  19. MFC CStdioFile简单用法
  20. 【元器件】2.无源晶振

热门文章

  1. python-元组数据类型-0222
  2. 05-sqlyog的安装与基本使用
  3. jquery-本地存储-cookie插件
  4. 编译安装MongoDB以及安装PHP的mongodb扩展
  5. 字符串转整数,不使用任何C语言库函数
  6. 【学习Android NDK开发】Java通过JNI调用native方法
  7. Intent各种flag解析。
  8. 创建局域网内远程git仓库,并将本地仓库push推到远程仓库中
  9. JDK与Java SE/EE/ME的区别
  10. PHP规范之PSR-1