让子进程等待父进程(Make child process wait for parent)
我必须在C中编写一个程序,它将
fork
一个新进程,然后使用该进程将pid
用于另一个函数。 但是我需要在子进程运行之前调用此函数,我不知道如何执行此操作。这是我正在尝试做的一些伪代码。
pid_t pid = fork(); if(in_child){ //In the child process //launch child application //somehow stop the child application before it actually executes any code } else{ //call my function with the child's pid //resume the child process //do other stuff }
如果您需要任何其他信息,请询问。 谢谢。
编辑:我无权访问孩子的代码。 我只是想运行一个可执行文件。
I have to write a program in C that will
fork
a new process and then use that processespid
for another function. However I need to call this function before the child process can run and I don't know how to do this.Here's some pseudo code of what I'm trying to do.
pid_t pid = fork(); if(in_child){ //In the child process //launch child application //somehow stop the child application before it actually executes any code } else{ //call my function with the child's pid //resume the child process //do other stuff }
If you need any additional info please ask. Thanks.
Edit: I do not have access to the code for the child. I'm just wanting to run an executable.
原文:https://stackoverflow.com/questions/16269975
最满意答案
你也可以实现
ngDoCheck
方法来检查有效性:ngDoCheck(value: string) { if (field.valid || field.pristine) { this.el.classList.remove('has-error'); } else { this.el.classList.add('has-error'); } }
这就是说你可以实现一个直接在元素上使用
ngClass
的包装组件。 像这样的东西:@Component({ selector: 'field', template: ` <div class="form-group form-group-sm" [ngClass]="{'has-error':state && !state.valid}"> <label for="for" class="col-sm-3 control-label">{{label}}</label> <div class="col-sm-8"> <!-- Input, textarea or select --> <ng-content></ng-content> <span *ngIf="state && !state.valid" class="help-block text-danger"> <span *ngIf="state.errors.required">The field is required</span> </span> </div> </div> ` }) export class FormFieldComponent { @Input() label: string; @Input() state: Control; }
您甚至可以通过使用
@ContentChild
修饰器直接引用ng-content
的控件来进一步:@Component({ (...) }) export class FormFieldComponent { @Input() label: string; @ContentChild(NgFormControl) state; (...) }
通过这种方式,您可以使用
ngFormControl
以这种方式定义输入(也可以使用ngControl
):<form [ngFormModel]="companyForm"> <field label="Name"> <input [ngFormControl]="companyForm.controls.name" [(ngModel)]="company.name"/> </field> </form>
有关更多详细信息,请参阅此文章(“表单域的表单组件”):
You could also implement the
ngDoCheck
method to check the validity:ngDoCheck(value: string) { if (field.valid || field.pristine) { this.el.classList.remove('has-error'); } else { this.el.classList.add('has-error'); } }
That said you could implement a wrapping component that leverages
ngClass
directly on the element. Something like that:@Component({ selector: 'field', template: ` <div class="form-group form-group-sm" [ngClass]="{'has-error':state && !state.valid}"> <label for="for" class="col-sm-3 control-label">{{label}}</label> <div class="col-sm-8"> <!-- Input, textarea or select --> <ng-content></ng-content> <span *ngIf="state && !state.valid" class="help-block text-danger"> <span *ngIf="state.errors.required">The field is required</span> </span> </div> </div> ` }) export class FormFieldComponent { @Input() label: string; @Input() state: Control; }
You can even go further by directly referencing the control from the
ng-content
using the@ContentChild
decorator:@Component({ (...) }) export class FormFieldComponent { @Input() label: string; @ContentChild(NgFormControl) state; (...) }
This way you would be able to define your input this way with
ngFormControl
(would also work withngControl
):<form [ngFormModel]="companyForm"> <field label="Name"> <input [ngFormControl]="companyForm.controls.name" [(ngModel)]="company.name"/> </field> </form>
See this article for more details (section "Form component for fields"):
相关问答
更多-
你能发布app-module.ts的代码吗?我怀疑你在@ngModule里面遗漏了什么比较那个视频...我怀疑它是FormsModule或ReactiveFormsModule之一 没看过视频......如果是Hello World类型的场景,你可能会使用FormsModule。 import {FormsModule, ReactiveFormsModule} from '@angular/forms'; NgModule({ .... imports: [ ..., FormsMod ...
-
您可以添加此样式: .has-error .form-control > .selectpicker { border-color: #a94442; -webkit-box-shadow: inset 0 1px 1px rgba(0,0,0,.075); box-shadow: inset 0 1px 1px rgba(0,0,0,.075); } 在这里看一个演示。 You can add this style: .has-error .form-control > .sel ...
-
将您的表单名称name =“email-form”更改为name =“emailForm”。 在文档之后,您应该使用以下内容 : required not an email 与其他两个相同。 ...
-
尝试这个注意: 如果用户提交的表单包含除性别之外的空字段,则它将返回true并将转到您的insert语句。 它将在每个if()语句中覆盖$valid变量的值。 您可以尝试使用此值来为$valid变量赋值: if(empty($fname) || empty($lname) || empty($age) || empty($gender)){ $valid = "false"; } else { $valid = "true"; } 由于输入字段中required = "required"属性,您的表单也会 ...
如何在Angular 2中的无效字段上显示“has-error”类(How to show the 'has-error' class on an invalid field in Angular 2)[2023-12-23]
你也可以实现ngDoCheck方法来检查有效性: ngDoCheck(value: string) { if (field.valid || field.pristine) { this.el.classList.remove('has-error'); } else { this.el.classList.add('has-error'); } } 这就是说你可以实现一个直接在元素上使用ngClass的包装组件。 像这样的东西: @Component({ selecto ...您可以尝试使用输入文本并通过自定义指令验证用户输入。 请参阅此链接以获得更好的解释: 如何只允许输入一个数字(数字和小数点)? 如果你想允许+和 - 用这样的东西修改正则表达式: [^0-9\-\.\+] you can try to use an input text and validate user input through a custom directive. See this link for a better explanation: How to allow only a number ...您可以使用ngModel验证器: .directive("smth", function($rootScope) { var link = function(scope, element, attrs, ngModelCtrl) { // Add custom validator ngModelCtrl.$validators["timeString"] = function(modelValue) { return !$rootScope. ...Angular 2中的日期无效(Invalid Date in Angular 2)[2023-01-08]
如果您引用的Microsoft JSON日期是'/Date(1224043200000)/'并且这将始终是格式,那么您可以使用RegExp提取数值并获取日期。 formatJsonDate(jsonDate) { return new Date(+(jsonDate.match(/\d+/)[0])); } If the Microsoft JSON Date you refer to is '/Date(1224043200000)/' and this will be always the f ...角度形式验证 - $ angular attribut in angular(Angular form validation - $invalid attribut in angular)[2022-02-07]
FormController检查表单输入上给出的规则。 例如 如果此输入为$pristine (未触及),则表单将无效。 您可以指定更多规则: 内置验证令牌: email,max,maxlength,min,minlength,number,pattern,required和url FormController checks for rules given on the form inputs. for example相关文章
更多- Hadoop下远程调试Child子进程
- 干干净净终结进程[转] Terminate process cleanly [reprint]
- zz Data Analysis Process
- 解决Hadoop抛出的Task process exit with nonzero status of 134异常
- Hadoop执行分布式Process
- multi-core solr deploy process(not complete)
- multi-core solr deploy process(not complete)
- Hadoop运行时错误:Task process exit with nonzero status of 1
- twitter storm 源码走读之5 -- worker进程内部消息传递处理和数据结构分析
- 启动Storm各个后台进程
最新问答
更多- 获取MVC 4使用的DisplayMode后缀(Get the DisplayMode Suffix being used by MVC 4)
- 如何通过引用返回对象?(How is returning an object by reference possible?)
- 矩阵如何存储在内存中?(How are matrices stored in memory?)
- 每个请求的Java新会话?(Java New Session For Each Request?)
- css:浮动div中重叠的标题h1(css: overlapping headlines h1 in floated divs)
- 无论图像如何,Caffe预测同一类(Caffe predicts same class regardless of image)
- xcode语法颜色编码解释?(xcode syntax color coding explained?)
- 在Access 2010 Runtime中使用Office 2000校对工具(Use Office 2000 proofing tools in Access 2010 Runtime)
- 从单独的Web主机将图像传输到服务器上(Getting images onto server from separate web host)
- 从旧版本复制文件并保留它们(旧/新版本)(Copy a file from old revision and keep both of them (old / new revision))
- 西安哪有PLC可控制编程的培训
- 在Entity Framework中选择基类(Select base class in Entity Framework)
- 在Android中出现错误“数据集和渲染器应该不为null,并且应该具有相同数量的系列”(Error “Dataset and renderer should be not null and should have the same number of series” in Android)
- 电脑二级VF有什么用
- Datamapper Ruby如何添加Hook方法(Datamapper Ruby How to add Hook Method)
- 金华英语角.
- 手机软件如何制作
- 用于Android webview中图像保存的上下文菜单(Context Menu for Image Saving in an Android webview)
- 注意:未定义的偏移量:PHP(Notice: Undefined offset: PHP)
- 如何读R中的大数据集[复制](How to read large dataset in R [duplicate])
- Unity 5 Heighmap与地形宽度/地形长度的分辨率关系?(Unity 5 Heighmap Resolution relationship to terrain width / terrain length?)
- 如何通知PipedOutputStream线程写入最后一个字节的PipedInputStream线程?(How to notify PipedInputStream thread that PipedOutputStream thread has written last byte?)
- python的访问器方法有哪些
- DeviceNetworkInformation:哪个是哪个?(DeviceNetworkInformation: Which is which?)
- 在Ruby中对组合进行排序(Sorting a combination in Ruby)
- 网站开发的流程?
- 使用Zend Framework 2中的JOIN sql检索数据(Retrieve data using JOIN sql in Zend Framework 2)
- 条带格式类型格式模式编号无法正常工作(Stripes format type format pattern number not working properly)
- 透明度错误IE11(Transparency bug IE11)
- linux的基本操作命令。。。